Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store


(PECL amqp >= Unknown)

AMQPQueue::consumeConsume messages from a queue


public void AMQPQueue::consume ( callable $callback [, int $flags = AMQP_NOPARAM ] )

Blocking function that will retrieve the next message from the queue as it becomes available and will pass it off to the callback.



A callback function to which the consumed message will be passed. The function must accept at a minimum one parameter, an AMQPEnvelope object, and an optional second parameter the AMQPQueue from which the message was consumed.

The AMQPQueue::consume will not return the processing thread back to the PHP script until the callback function returns FALSE.


A bitmask of any of the flags: AMQP_NOACK.


Throws AMQPChannelException if the channel is not open.

Throws AMQPConnectionException if the connection to the broker was lost.

Return Values


Example #1 AMQPQueue::consume example


/* Create a connection using all default credentials: */
$connection = new AMQPConnection();

$channel = new AMQPChannel($connection);

/* create a queue object */
$queue = new AMQPQueue($channel);

//declare the queue

$i 0;
processMessage($envelope$queue) {
"Message $i: " $envelope->getBody() . "\n";
        if (
$i 10) {
// Bail after 10 messages
return false;

// Consume messages on queue


PHP Manual