Yet another Amazon SQS Sample in PHP

Sample Code & Libraries>Amazon SQS>Yet another Amazon SQS Sample in PHP
Community Contributed Software

  • Amazon Web Services provides links to these packages as a convenience for our customers, but software not authored by an "@AWS" account has not been reviewed or screened by AWS.
  • Please review this software to ensure it meets your needs before using it.

This code provides a basic sample for how to use Amazon SQS with PHP 5.


Submitted By: tommylacroix
AWS Products Used: Amazon SQS
Language(s): PHP
License: Apache License 2.0
Created On: May 30, 2008 1:47 PM GMT
Last Updated: September 21, 2008 8:11 PM GMT

About This Sample

  • A PHP Query API sample to demonstrate creating a queue, sending messages, receiving messages, and deleting messages.
  • Based on the 2008-01-01 API version (Query).
  • Based on Amazon SQS Sample in PHP by Justin@AWS
  • Minor improvements made to increase performance and to drop dependencies of sqs.client.php:
    • PEAR::HTTP_Request has been replaced by CURL or HTTP URL Wrappers, depending on availability
    • PEAR::Crypt_HMAC has been replaced by hash or mhash PECL, depending on availability
    • A standalone HMAC function has been included, so the library can run without hash or mhash PECL
    • The library uses POST mode rather than GET if the query string is longer than 1k
    • The HMAC conversion from hexadecimal to binary is done with pack(), rather than with a for-loop
    • PHPDoc blocks have been added

The PHP sample code includes an example file called sqs.test.php that performs basic SQS actions. We explain how to run that example. We also walk through the contents of that file. After you're familiar with the contents of sqs.test.php, you can modify the file as you'd like to suit your needs.


  • You must have a valid Amazon Web Services developer account (go to to sign up for one).
  • You must be signed up to use Amazon SQS (go to to sign up for the service).
  • PHP 5, which includes access to the SimpleXML extension (to download it, go to
  • Requires either CURL or HTTP URL Wrapper for HTTP communication
  • For HMAC, makes use of hash or mhash PECL functions, or falls back on a standalone function using sha1() if not available.

Running the Sample

  1. Enter your AWS credentials in sqs.test.php.
  2. Open sqs.test.php.
  3. Note: initial page load may take a few seconds as a new queue will be created.
©2017, Amazon Web Services, Inc. or its affiliates. All rights reserved.