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

Message operations

After a queue is created, simple messages can be sent into the queue then received at a later point in time. Messages can be up to 8KB in length. If longer messages are needed please see S3. There is no limit to the number of messages a queue can contain.

  • sent($queue_url, $message) send the $message to the $queue_url SQS queue URL.

    Example 780. Zend_Service_Amazon_Sqs Message Send Example

    <?php
    $sqs 
    = new Zend_Service_Amazon_Sqs($my_aws_key$my_aws_secret_key);
    $queue_url $sqs->create('test_queue');
    $sqs->send($queue_url'this is a test message');

  • receive($queue_url) retrieves messages from the queue.

    Example 781. Zend_Service_Amazon_Sqs Message Receive Example

    <?php
    $sqs 
    = new Zend_Service_Amazon_Sqs($my_aws_key$my_aws_secret_key);
    $queue_url $sqs->create('test_queue');
    $sqs->send($queue_url'this is a test message');
    foreach (
    $sqs->receive($queue_url) as $message) {
        echo 
    "got message ".$message['body'].'<br/>';
    }

  • deleteMessage($queue_url, $handle) deletes a message from a queue. A message must first be received using the receive() method before it can be deleted.

    Example 782. Zend_Service_Amazon_Sqs Message Delete Example

    <?php
    $sqs 
    = new Zend_Service_Amazon_Sqs($my_aws_key$my_aws_secret_key);
    $queue_url $sqs->create('test_queue');
    $sqs->send($queue_url'this is a test message');
    foreach (
    $sqs->receive($queue_url) as $message) {
        echo 
    "got message ".$message['body'].'<br/>';

        if (
    $sqs->deleteMessage($queue_url$message['handle'])) {
            echo 
    "Message deleted";
        }
        else {
            echo 
    "Message not deleted";
        }
    }

Zend Framework