Skip to content
This repository

PHP client for IronMQ.

tree: ab1badb396

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .gitignore
Octocat-spinner-32 IronMQ.class.php
Octocat-spinner-32 LICENSE License nice formatting March 06, 2012
Octocat-spinner-32 README.md
Octocat-spinner-32 build.php
Octocat-spinner-32 composer.json
Octocat-spinner-32 iron_mq.phar
Octocat-spinner-32 sample_config.ini
Octocat-spinner-32 simpleTest.php
README.md

PHP language binding for IronMQ

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

See How It Works

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 precompiled phar archive:

Copy iron_mq.phar to target directory and include it:

<?php
require_once "phar://iron_mq.phar";

Please note, phar extension available by default only from php 5.3.0 For php 5.2 you should install phar manually or use second option.

Using classes directly

  1. Copy IronMQ.class.php to target directory
  2. Grab IronCore.class.php there and copy to target directory
  3. Include both of them:
<?php
require_once "IronCore.class.php"
require_once "IronMQ.class.php"

Configure

Three ways to configure IronMQ:

  • Passing array with options:
<?php
$ironmq = new 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('config.ini');
  • 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

The Basics

Push a message on the queue:

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

More complex example:

<?php
$ironmq->postMessage("test_queue", array(
    "body" => "Test Message",
    "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.
));

Pop a message off the queue:

<?php
$ironmq->getMessage("test_queue");

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).

Delete a message from the queue:

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

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

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

Full Documentation

You can find more documentation here:

Something went wrong with that request. Please try again.