Prerequisites
- PHP 5 with cURL support
Project Site
Up to date information about this package can be found at the simple-aws project site.
Documentation
Authentication
AWS requires the use of an access key and a secret key to maintain security on your own AWS account. The SQS package makes use of an .ini file for storing these credentials.
Currently, this .ini file is expected to be located at "/etc/amazon/aws.ini" on your server. If you want to change this location, it can be edited in the Services_Amazon_Account class:
private $_aws_ini_file = '/etc/amazon/aws.ini';
Managing Queues
The Services_Amazon?_SQS_QueueManager? class can be used for listing, creating, deleting, or managing properties on your queues:
$manager = new Services_Amazon_SQS_QueueManager();
// Get a list of all queues in the account.
$list = $manager->listQueues();
// Get a list of queues that start with the prefix "db-jobs-".
$list = $manager->listQueues("db-jobs-");
// Add a new queue for managing changes to usernames (arbitrary example).
$success = $manager->createQueue("db-jobs-username-changes");
// Remove an obsolete queue. Queues are referenced by full URLs.
$success = $manager->deleteQueue("http://queue.amazonaws.com/db-jobs-moderate-images");
Command-line Manager
Additionally, there is a PHP script in the /bin directory that can be used for managing queues. The bootstrap.php file in /bin is used for setting up the proper PHP include path and defining an autoload function. It should be customized for your own environment.
Usage:
$ ./sqs A command-line interface to Amazon's Simple Queue Service. Usage: ./sqs [options] Options: --list List all available queues in account. --add=NAME Add a new queue. --delete=URL Delete a queue. -h, --help show this help message and exit --version show the program version and exit
Examples:
$ ./sqs --list QUEUE ITEMS (APPROX.) VIS. TIMEOUT http://queue.amazonaws.com/queue-one 257 30 http://queue.amazonaws.com/queue-two 108 30 $ ./sqs --add=queue-three New queue has been added. It may take up to 60 seconds for it to appear in your list of queues. $ ./sqs --list QUEUE ITEMS (APPROX.) VIS. TIMEOUT http://queue.amazonaws.com/queue-one 257 30 http://queue.amazonaws.com/queue-two 108 30 http://queue.amazonaws.com/queue-three 0 30
Using Queues
Add new jobs to a queue, typically as serialized data.
// Get an object for a DB job queue.
$queue = new Services_Amazon_SQS_Queue("http://queue.amazonaws.com/db-jobs-username-changes");
// Create a job to be added to the queue.
$job = serialize( array("old_username" => "spanks543", "new_username" => "spanky") );
$result = $queue->push($job);
Job processor script will pick up an item from the queue, complete the job, then delete the item from the queue.
$queue = new Services_Amazon_SQS_Queue("http://queue.amazonaws.com/db-jobs-username-changes");
// Grab a task from the queue (makes it invisible to other job processors for a time limit).
$messages = $queue->pop();
$job = unserialize($messages[0]['message']);
// ... Process the job ...
// Delete the completed job from the queue.
$queue->delete($messages[0]['handle']);