• Stars
    star
    89
  • Rank 372,305 (Top 8 %)
  • Language
    PHP
  • License
    BSD 2-Clause "Sim...
  • Created about 13 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP client for IronMQ.

IronMQ v4 PHP Client Library

IronMQ is an elastic message queue for managing data and event flow within cloud applications and between systems.

This library uses IronMQ API v3.

Branches

If you're using laravel and see "Class IronMQ not found" error set iron_mq version to 1.* and install/update dependencies

  • 1.* - Laravel 4.0/4.1/4.2/5.0 compatible, PHP 5.2 compatible version. No namespaces. Using IronMQv2 servers (deprecated).
  • 2.* - Laravel 5.1/5.2 compatible, PSR-4 compatible version. With namespaces. Using IronMQv2 servers (deprecated).
  • 3.* - Laravel 4.0/4.1/4.2/5.0 compatible, PHP 5.2 compatible version. IronMQv3.
  • 4.* - (recommended) Laravel 5.1/5.2 compatible, PSR-4 compatible version. With namespaces. IronMQv3. Current default.
  • master branch - same as 4.*

Update notes

  • 1.3.0 - changed argument list in methods postMessage and postMessages. Please revise code that uses these methods.
  • 1.4.5 - added getMessagePushStatuses and deleteMessagePushStatus methods.
  • 2.0.0 - version 2.0 introduced some backward incompatible changes. IronMQ client finally PSR-4 compatible and using namespaces & other php 5.3 stuff. If you're migrating from previous (1.x) version, please carefully check how iron_mq / iron_core classes loaded. If you need some 1.x features like .phar archives, use latest 1.x stable version: https://github.com/iron-io/iron_mq_php/releases/tag/1.5.3

Getting Started

Get credentials

To start using iron_mq_php, you need to sign up and get an oauth token.

  1. Go to http://iron.io/ and sign up.
  2. Get an Oauth Token at http://hud.iron.io/tokens

--

Install iron_mq_php

There are two ways to use iron_mq_php:

Using composer

Create composer.json file in project directory:

{
    "require": {
        "iron-io/iron_mq": "2.*"
    }
}

Do composer install (install it if needed: https://getcomposer.org/download/)

And use it:

require __DIR__ . '/vendor/autoload.php';

$ironmq = new \IronMQ\IronMQ();
Using classes directly (strongly not recommended)
  1. Copy classes from src to target directory
  2. Grab IronCore classes there and copy to target directory
  3. Include them all.
require 'src/HttpException.php';
require 'src/IronCore.php';
require 'src/IronMQ.php';
require 'src/IronMQException.php';
require 'src/IronMQMessage.php';
require 'src/JsonException.php';

$ironmq = new \IronMQ\IronMQ();

--

Configure

Three ways to configure IronMQ:

  • Passing array with options:
<?php
$ironmq = new \IronMQ\IronMQ(array(
    "token" => 'XXXXXXXXX',
    "project_id" => 'XXXXXXXXX'
));
  • Passing ini file name which stores your configuration options. Rename sample_config.ini to config.ini and include your Iron.io credentials (token and project_id):
<?php
$ironmq = new \IronMQ\IronMQ('config.json');
  • Automatic config search - pass zero arguments to constructor and library will try to find config file in following locations:

    • iron.ini in current directory
    • iron.json in current directory
    • IRON_MQ_TOKEN, IRON_MQ_PROJECT_ID and other environment variables
    • IRON_TOKEN, IRON_PROJECT_ID and other environment variables
    • .iron.ini in user's home directory
    • .iron.json in user's home directory

--

Keystone Authentication

Via Configuration File

Add keystone section to your iron.json file:

{
  "project_id": "57a7b7b35e8e331d45000001",
  "keystone": {
    "server": "http://your.keystone.host/v2.0/",
    "tenant": "some-group",
    "username": "name",
    "password": "password"
  }
}

In Code

$keystone = array(
    "server" => "http://your.keystone.host/v2.0/",
    "tenant" => "some-gorup",
    "username" => "name",
    "password" => "password"
);
$ironmq = new \IronMQ\IronMQ(array(
    "project_id" => '57a7b7b35e8e331d45000001',
    "keystone" => $keystone
));

The Basics

Post a Message to the Queue

<?php
$ironmq->postMessage($queue_name, "Hello world");

More complex example:

<?php
$ironmq->postMessage($queue_name, "Test Message", array(
    "timeout" => 120, # Timeout, in seconds. After timeout, item will be placed back on queue. Defaults to 60.
    "delay" => 5, # The item will not be available on the queue until this many seconds have passed. Defaults to 0.
    "expires_in" => 2*24*3600 # How long, in seconds, to keep the item on the queue before it is deleted.
));

Post multiple messages in one API call:

<?php
$ironmq->postMessages($queue_name, array("Message 1", "Message 2"), array(
    "timeout" => 120
));

--

Reserve a Message

<?php
$ironmq->reserveMessage($queue_name);

When you pop/get a message from the queue, it will NOT be deleted. It will eventually go back onto the queue after a timeout if you don't delete it (default timeout is 60 seconds).

Reserve multiple messages in one API call:

<?php
$ironmq->reserveMessages($queue_name, 3);

Reservation Id is needed for operations like delete, touch or release a message. It could be obtained from message model after reserving it:

<?php
$message = $ironmq->reserveMessage($queue_name);
$reservation_id = $message->reservation_id;

--

Delete a Message from the Queue

<?php
$ironmq->deleteMessage($queue_name, $message_id, $reservation_id);

If message isn't reserved, you don't need to provide reservation id

<?php
$ironmq->deleteMessage($queue_name, $message_id);

Delete a message from the queue when you're done with it.

Delete multiple messages in one API call:

<?php
$ironmq->deleteMessages($queue_name, array("xxxxxxxxx", "xxxxxxxxx"));

Delete multiple messages specified by messages id array.

It's also possible to delete array of message objects:

<?php
$messages = $ironmq->reserveMessages($queue_name, 3);
$ironmq->deleteMessage($queue_name, $messages);

--

Troubleshooting

http error: 0

If you see Uncaught exception 'Http_Exception' with message 'http error: 0 | ' it most likely caused by misconfigured cURL https sertificates. There are two ways to fix this error:

  1. Disable SSL sertificate verification - add this line after IronMQ initialization: $ironmq->ssl_verifypeer = false;
  2. Switch to http protocol - add this to configuration options: protocol = http and port = 80
  3. Fix the error! Recommended solution: download actual certificates - cacert.pem and add them to php.ini:
[PHP]

curl.cainfo = "path\to\cacert.pem"

--

Updating notes

  • 1.3.0 - changed argument list in methods postMessage and postMessages. Please revise code that uses these methods.
  • 1.4.5 - added getMessagePushStatuses and deleteMessagePushStatus methods.

--

Queues

IronMQ Client

IronMQ is based on IronCore and provides easy access to the whole IronMQ API.

<?php
$ironmq = new \IronMQ\IronMQ(array(
    "token" => 'XXXXXXXXX',
    "project_id" => 'XXXXXXXXX'
));

--

List Queues

This code will return first 30 queues sorted by name.

<?php
$queues = $ironmq->getQueues();

Optional parameters:

  • per_page: number of elements in response, default is 30.
  • previous: this is the last queue on the previous page, it will start from the next one. If queue with specified name doesnโ€™t exist result will contain first per_page queues that lexicographically greater than previous

Assume you have queues named "a", "b", "c", "d", "e". The following code will list "c", "d" and "e" queues:

<?php
$queues = $ironmq->getQueues('b', 3);

--

Retrieve Queue Information

<?php
$qinfo = $ironmq->getQueue($queue_name);

--

Delete a Message Queue

<?php
$response = $ironmq->deleteQueue($queue_name);

--

Post Messages to a Queue

Single message:

<?php
$ironmq->postMessage($queue_name, "Test Message", array(
    'delay' => 2,
    'expires_in' => 2*24*3600 # 2 days
));

Multiple messages:

<?php
$ironmq->postMessages($queue_name, array("Lorem", "Ipsum"), array(
    "delay" => 2,
    "expires_in" => 2*24*3600 # 2 days
));

Optional parameters (3rd, array of key-value pairs):

  • delay: The item will not be available on the queue until this many seconds have passed. Default is 0 seconds. Maximum is 604,800 seconds (7 days).

  • expires_in: How long in seconds to keep the item on the queue before it is deleted. Default is 604,800 seconds (7 days). Maximum is 2,592,000 seconds (30 days).

  • timeout: Deprecated. Can no longer set timeout when posting a message, only when reserving one.

--

Get Messages from a Queue

Single message:

<?php
$message = $ironmq->reserveMessage($queue_name, $timeout);

Multiple messages:

<?php
$message = $ironmq->reserveMessages($queue_name, $count, $timeout, $wait);

Optional parameters:

  • $count: The maximum number of messages to get. Default is 1. Maximum is 100.

  • $timeout: After timeout (in seconds), item will be placed back onto queue. You must delete the message from the queue to ensure it does not go back onto the queue. If not set, value from POST is used. Default is 60 seconds. Minimum is 30 seconds. Maximum is 86,400 seconds (24 hours).

  • $wait: Time to long poll for messages, in seconds. Max is 30 seconds. Default 0.

--

Touch a Message on a Queue

Touching a reserved message returns new reservation with specified or default timeout.

<?php
$ironmq->touchMessage($queue_name, $message_id, $reservation_id, $timeout);

--

Release Message

<?php
$ironmq->releaseMessage($queue_name, $message_id, $reservation_id, $delay);

Parameters:

  • $delay: The item will not be available on the queue until this many seconds have passed. Default is 0 seconds. Maximum is 604,800 seconds (7 days).

--

Delete a Message from a Queue

<?php
$ironmq->deleteMessage($queue_name, $message_id, $reservation_id);

--

Peek Messages from a Queue

Peeking at a queue returns the next messages on the queue, but it does not reserve them.

Single message:

<?php
$message = $ironmq->peekMessage($queue_name);

Multiple messages:

<?php
$messages = $ironmq->peekMessages($queue_name, $count);

--

Clear a Queue

<?php
$ironmq->clearQueue($queue_name);

--

Push Queues

IronMQ push queues allow you to setup a queue that will push to an endpoint, rather than having to poll the endpoint. Here's the announcement for an overview.

Create a Queue

<?php
$params = array(
    "message_timeout" => 120,
    "message_expiration" => 24 * 3600,
    "push" => array(
        "subscribers" => array(
            array("url" => "http://your.first.cool.endpoint.com/push", "name" => "first"),
            array("url" => "http://your.second.cool.endpoint.com/push", "name" => "second")
        ),
        "retries" => 4,
        "retries_delay" => 30,
        "error_queue" => "error_queue_name"
    )
);

$ironmq->createQueue($queue_name, $params);

Options:

  • type: String or symbol. Queue type. :pull, :multicast, :unicast. Field required and static.
  • message_timeout: Integer. Number of seconds before message back to queue if it will not be deleted or touched.
  • message_expiration: Integer. Number of seconds between message post to queue and before message will be expired.

The following parameters are all related to Push Queues:

  • push: subscribers: An array of subscriber hashes containing a name and a url required fields, and optional headers hash. headers's keys are names and values are means of HTTP headers. This set of subscribers will replace the existing subscribers. To add or remove subscribers, see the add subscribers endpoint or the remove subscribers endpoint. See below for example json.
  • push: retries: How many times to retry on failure. Default is 3. Maximum is 100.
  • push: retries_delay: Delay between each retry in seconds. Default is 60.
  • push: error_queue: String. Queue name to post push errors to.

--

Update Queue Information

Same as create queue. A push queue couldn't be changed into a pull queue, so vice versa too.

Add/Remove Subscribers on a Queue

Add subscribers to Push Queue:

<?php

$ironmq->addSubscriber($queue_name, array(
       "url" => "http://cool.remote.endpoint.com/push",
       "name" => "subscriber_name",
       "headers" => array(
          "Content-Type" => "application/json"
       )
   )
);

$ironmq->addSubscribers($queue_name, array(
        array(
            "url" => "http://first.remote.endpoint.com/push",
            "name" => "first"),
        array(
            "url" => "http://second.remote.endpoint.com/push",
            "name" => "second")
    )
);

--

Replace Subscribers on a Queue

Sets list of subscribers to a queue. Older subscribers will be removed.

<?php

$ironmq->replaceSubscriber($queue_name, array(
       "url" => "http://cool.remote.endpoint.com/push",
       "name" => "subscriber_name"
   )
);

$ironmq->addSubscribers($queue_name, array(
        array(
            "url" => "http://first.remote.endpoint.com/push",
            "name" => "first"),
        array(
            "url" => "http://second.remote.endpoint.com/push",
            "name" => "second")
    )
);

Remove Subscribers from a Queue

Remove subscriber from a queue. This is for Push Queues only.

<?php

$ironmq->removeSubscriber($queue_name, array(
       "name" => "subscriber_name"
   )
);

$ironmq->removeSubscribers($queue_name, array(
        array("name" => "first"),
        array("name" => "second")
    )
);

Get Message Push Status

<?php
$response = $ironmq->postMessage('push me!');

$message_id = $response["ids"][0];
$statuses = $ironmq->getMessagePushStatuses($queue_name, $message_id);

Returns an array of subscribers with status.

--

Acknowledge, That Push Message Is Processed

This method could be used to acknowledgement process of push messages. See IronMQ v3 documentation on long-processing for further information.

<?php
$ironmq->deletePushMessage($queue_name, $message_id, $reservation_id, $subscriber_name);

--

Further Links


ยฉ 2011 - 2013 Iron.io Inc. All Rights Reserved.

More Repositories

1

functions

IronFunctions - the serverless microservices platform by
Go
3,182
star
2

dockers

Uber tiny Docker images for all the things.
HTML
1,591
star
3

dockerworker

The new IronWorker workflow examples. Test locally, then upload and start queuing jobs!
Scala
233
star
4

functions-ui

User interface for IronFunctions - http://github.com/iron-io/functions
Vue
95
star
5

iron_go

Iron.io API libraries
Go
79
star
6

lambda

All Iron.io open source AWS Lambda code.
Go
69
star
7

iron_worker_ruby_ng

Next Gen Ruby gem for IronWorker
Ruby
58
star
8

iron_worker_php

PHP client for IronWorker
PHP
56
star
9

iron_mq_node

CoffeeScript
51
star
10

laraworker

Easily add IronWorker to Laravel Applications
PHP
45
star
11

iron_mq_java

Java library for IronMQ.
Java
44
star
12

iron_worker_python

Python client for IronWorker
Python
42
star
13

iron_worker_ruby

Official IronWorker gem.
Ruby
39
star
14

iron_mq_ruby

Ruby library for IronMQ.
Ruby
35
star
15

ironcli

Command line tool for the Iron.io platform.
Go
35
star
16

iron_mq_python

Python client for IronMQ.
Python
35
star
17

docs

Iron.io Dev Center documentation.
CSS
30
star
18

iron_celery

IronMQ broker and IronCache results store for Python's Celery project.
Python
30
star
19

iron_worker_rails_example

Rails Application Demonstrating IronWorker Usage
Ruby
26
star
20

iron_worker_node

CoffeeScript
25
star
21

rest

HTTP/REST client wrapper that provides a standard interface for making http requests using different http clients.
Ruby
23
star
22

iron_core_php

PHP
19
star
23

iron_dotnet

C#
18
star
24

picasso

Project Picasso (Functions-as-a-Service) for OpenStack
17
star
25

heroku_sinatra_example

This is an example Sinatra application ready to run on Heroku using IronWorker and IronMQ Add Ons.
Ruby
17
star
26

iron_go3

Go lib for IronMQ v3.
Go
15
star
27

iron_cache_php

PHP
15
star
28

iron_cache_ruby

Ruby client for IronCache
Ruby
14
star
29

runner

Go
11
star
30

iron_worker_java

Java
9
star
31

iron_cache_python

Python
9
star
32

functions_js

JavaScript library for IronFunctions.
JavaScript
9
star
33

ironcasts-series-1

All code examples used in IronWorker 101 in IronCast Episode 1 to Episode 4
Ruby
8
star
34

slackbots

A repository of Slack bots that run on IronWorker
Ruby
8
star
35

abt

ABT - Always Be Testing - A ruby gem that uses IronWorker to continously run tests.
Ruby
8
star
36

functions_go

Go library for IronFunctions.
Go
7
star
37

golog

Simple logging helper for Go.
Go
7
star
38

iron_mq_go

DEPRECATED! Use https://github.com/iron-io/iron_go
Go
7
star
39

iron_core_ruby

Ruby
7
star
40

iron_mq_clojure

Clojure client for IronMQ
Clojure
7
star
41

iron_cache_rails

Rails cache store and session store using IronCache by www.iron.io
Ruby
7
star
42

heroku-iron-celery-demo

A demo of running Celery on Heroku. Downloads an RSS feed and parses the items. http://iron-celery-demo.herokuapp.com
JavaScript
7
star
43

workers

Ruby
6
star
44

iron_core_python

Python
6
star
45

iron_core_node

CoffeeScript
6
star
46

ironmq-openshift-quickstart

Shell
5
star
47

ironcasts-series-1-samplecode

Ruby
5
star
48

gosqs

SQS interface for Go
Go
5
star
49

issues

For Iron.io services issue tracking. Public facing issue tracking for behind the scenes issues.
5
star
50

rackspace-django-demo

Python
5
star
51

lambda-vs-ironworker

Examples of using Lambda and IronWorker to do the same thing.
JavaScript
4
star
52

functions_ruby

Ruby library for IronFunctions.
Ruby
4
star
53

newrelic_platform

Ruby library for the new New Relic Platform - http://newrelic.com/platform
Ruby
4
star
54

image_processor

PHP
4
star
55

glock

Boom
Go
4
star
56

rails-nginx-unicorn

A dead simple base image for dockerizing Rails apps using unicorn/foreman/nginx
Nginx
4
star
57

iron_cache_dotnet

C#
3
star
58

microcontainers

Reference site for Microcontainers.
3
star
59

koders

A Ruby app using Sinatra and IronWorker to pull top Stackoverflow users then finds the languages they use on Github to get the top languages for the top SO users.
JavaScript
3
star
60

iron_combine

Ruby
3
star
61

iron-worker-examples

Top uses of IW with examples
HTML
3
star
62

gridiron

Python
2
star
63

heroku_iron_boomi_salesforce

Heroku -> Iron.io -> Boomi -> Salesforce Integration Demo
JavaScript
2
star
64

python-picassoclient

OpenStack SDK & CLI plugin for Picasso (Functions-as-a-Service)
2
star
65

splunk-ironmq-mi

Python
2
star
66

simple_worker_redirect

Redirects SimpleWorker to IronWorker
Ruby
2
star
67

logspout-statsd

A statsd adapter for logspout.
Go
2
star
68

worker_ruby

Ruby sdk for Titan.
Ruby
2
star
69

iron_cache_node

CoffeeScript
1
star
70

newrelic_parse_plugin

A New Relic Platform agent for Parse.
Ruby
1
star
71

maven

For hosting our java jars for Maven central.
Shell
1
star
72

worker_go

Go library for Titan.
Go
1
star
73

gobson_temp

Go
1
star
74

fn-go

A library for handling Go Language functions input and output
Go
1
star
75

monger

Go
1
star
76

ironmq-openshift-cartridge

Ruby
1
star
77

r-lang-worker-example

Hello world for R on IronWorker
R
1
star
78

iron_twilio_insanity

Iron.io and Twilio present: Beachbody Insanity Reminder
Ruby
1
star
79

codegen

JavaScript
1
star
80

sfbeta

Ruby
1
star
81

iron_mq_rust

โš™๏ธ Rust client for IronMQ
Rust
1
star
82

iron_mq_groovy

Groovy client for IronMQ
Groovy
1
star
83

worker_js

JavaScript
1
star
84

platform_performance

PHP
1
star
85

function-fork-me

An example function to fork and modify.
JavaScript
1
star
86

newrelic_ironmq_plugin

A New Relic Platform agent for IronMQ.
Ruby
1
star
87

iron_core_java

1
star
88

iron_consumer

Ruby
1
star
89

php_example_app

A PHP application that uses Iron.io services.
PHP
1
star
90

build_worker

Standard build worker for doing remote builds on IronWorker.
Ruby
1
star
91

newrelic_airbrake_plugin

A New Relic Platform agent for Airbrake.
Ruby
1
star
92

buckets

Go
1
star
93

ironfunctions-murano

Murano application package for IronFunctions on OpenStack
1
star
94

newrelic_saas_agent

Template for easily creating NewRelic Platform agents for SaaS services. No servers required.
Ruby
1
star