Skip to content

Instantly share code, notes, and snippets.

Last active December 6, 2021 22:51
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Sending and receiving messages from/to AWS SQS via PHP
// curl -sS | php
// php composer.phar require aws/aws-sdk-php
// export AWS_ACCESS_KEY_ID=...
require_once 'vendor/autoload.php';
$sdk = new \Aws\Sdk();
$sqsClient = $sdk->createSqs(['region' => 'eu-west-1', 'version' => '2012-11-05']);
echo "Sending message\n";
'QueueUrl' => $queueUrl,
'MessageBody' => 'Hello World!',
echo "Receiving messages\n";
$result = $sqsClient->receiveMessage([
'AttributeNames' => ['All'],
'MaxNumberOfMessages' => 10,
'QueueUrl' => $queueUrl,
foreach ($result->search('Messages[]') as $message) {
echo "- Message: {$message['Body']} (Id: {$message['MessageId']})\n";
echo "Deleting messages\n";
foreach ($result->search('Messages[]') as $message) {
'QueueUrl' => $queueUrl,
'ReceiptHandle' => $message['ReceiptHandle']
echo "- Deleted: {$message['MessageId']})\n";
Copy link

abdonor commented Apr 3, 2018

Very good, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment