Introduction | Zend_Queue Programmer's Reference Guide | Framework

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

1. // For configuration options
2. // @see Zend_Queue_Adapater::__construct()
3. $options = array(
4. 'name' => 'queue1',
5. );
7. // Create an array queue
8. $queue = new Zend_Queue('Array', $options);
10. // Get list of queues
11. foreach ($queue->getQueues() as $name) {
12. echo $name, "\n";
13. }
15. // Create a new queue
16. $queue2 = $queue->createQueue('queue2');
18. // Get number of messages in a queue (supports Countable interface from SPL)
19. echo count($queue);
21. // Get up to 5 messages from a queue
22. $messages = $queue->receive(5);
24. foreach ($messages as $i => $message) {
25. echo $message->body, "\n";
27. // We have processed the message; now we remove it from the queue.
28. $queue->deleteMessage($message);
29. }
31. // Send a message to the currently active queue
32. $queue->send('My Test Message');
34. // Delete a queue we created and all of it's messages
35. $queue->deleteQueue('queue2');

Introduction | Zend_Queue Programmer's Reference Guide | Framework