PhpRiot
Follow phpriot on Twitter
Sponsored Link
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
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

Getting Started

Once you have registered with Amazon SQS, you're ready to create your queue and store some messages on SQS. Each queue can contain unlimited amount of messages, identified by name.

The following example demonstrates creating a queue, storing and retrieving messages.

Example 758. Zend_Service_Amazon_Sqs Usage Example

<?php
$sqs 
= new Zend_Service_Amazon_Sqs($my_aws_key$my_aws_secret_key);

$queue_url $sqs->create('test');

$message 'this is a test';
$message_id $sqs->send($queue_url$message);

foreach (
$sqs->receive($queue_url) as $message) {
    echo 
$message['body'].'<br/>';
}

Since the Zend_Service_Amazon_Sqs service requires authentication, you should pass your credentials (AWS key and secret key) to the constructor. If you only use one account, you can set default credentials for the service:

<?php
Zend_Service_Amazon_Sqs
::setKeys($my_aws_key$my_aws_secret_key);
$sqs = new Zend_Service_Amazon_Sqs();

Zend Framework