PhpRiot
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

API Examples

This topic lists some examples of using the Zend_Service_WindowsAzure_Storage_Queue class. Other features are available in the download package, as well as a detailed API documentation of those features.

Creating a queue

Using the following code, a queue can be created on development storage.

Example 904. Creating a queue

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Queue();
$result $storageClient->createQueue('testqueue');

echo 
'Queue name is: ' $result->Name;

Deleting a queue

Using the following code, a queue can be removed from development storage.

Example 905. Deleting a queue

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Queue();
$storageClient->deleteQueue('testqueue');

Adding a message to a queue

Using the following code, a message can be added to a queue on development storage. Note that the queue has already been created before.

Example 906. Adding a message to a queue

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Queue();

// 3600 = time-to-live of the message, if omitted defaults to 7 days
$storageClient->putMessage('testqueue''This is a test message'3600);

Reading a message from a queue

Using the following code, a message can be read from a queue on development storage. Note that the queue and message have already been created before.

Example 907. Reading a message from a queue

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Queue();

// retrieve 10 messages at once
$messages $storageClient->getMessages('testqueue'10);

foreach (
$messages as $message) {
    echo 
$message->MessageText "\r\n";
}

The messages that are read using getMessages() will be invisible in the queue for 30 seconds, after which the messages will re-appear in the queue. To mark a message as processed and remove it from the queue, use the deleteMessage() method.

Example 908. Marking a message as processed

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Queue();

// retrieve 10 messages at once
$messages $storageClient->getMessages('testqueue'10);

foreach (
$messages as $message) {
    echo 
$message "\r\n";

    
// Mark the message as processed
    
$storageClient->deleteMessage('testqueue'$message);
}

Check if there are messages in a queue

Using the following code, a queue can be checked for new messages. Note that the queue and message have already been created before.

Example 909. Check if there are messages in a queue

<?php
$storageClient 
= new Zend_Service_WindowsAzure_Storage_Queue();

// retrieve 10 messages at once
$messages $storageClient->peekMessages('testqueue'10);

foreach (
$messages as $message) {
    echo 
$message->MessageText "\r\n";
}

Note that messages that are read using peekMessages() will not become invisible in the queue, nor can they be marked as processed using the deleteMessage() method. To do this, use getMessages() instead.

Zend Framework