42.2. Example usage

The below example of Zend_Queue shows a variety of features, including queue creation, queue retrieval, message retrieval, message deletion, and sending messages.

// For configuration options
// @see Zend_Queue_Adapater::__construct()
$options = array(
    'name' => 'queue1',

// Create an array queue
$queue = new Zend_Queue('Array', $options);

// Get list of queues
foreach ($queue->getQueues() as $name) {
    echo $name, "\n";

// Create a new queue
$queue2 = $queue->createQueue('queue2');

// Get number of messages in a queue (supports Countable interface from SPL)
echo count($queue);

// Get up to 5 messages from a queue
$messages = $queue->receive(5);

foreach ($messages as $i => $message) {
    echo $message->body, "\n";

    // We have processed the message; now we remove it from the queue.

// Send a message to the currently active queue
$queue->send('My Test Message');

// Delete a queue we created and all of it's messages

Previous topic


Next topic



© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.