Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Message Queue
    • Quick start
    • Supported tools
      • Python
      • Node.js
      • PHP
      • Celery
      • JMS
      • Laravel
      • Symfony
      • Terraform
      • Golang
  • Access management
  • Pricing policy
  • Terraform reference
  • Audit Trails events
  • Monitoring metrics
  • Public materials
  • FAQ

In this article:

  • Installation
  • Getting started
  • Example
  1. Getting started
  2. Code examples
  3. PHP

Example of using Yandex Message Queue on PHP

Written by
Yandex Cloud
Improved by
Updated at May 13, 2024
View in Markdown
  • Installation
  • Getting started
  • Example

With AsyncAws, you can manage Message Queue message queues and send and receive messages.

InstallationInstallation

Install the AsyncAws library:

composer require async-aws/sqs ^1.9

Getting startedGetting started

  1. Create a service account.
  2. Assign the editor role to the service account.
  3. Create a static access key.

Set the environment variables:

export AWS_ACCESS_KEY_ID="<access_key_ID>"
export AWS_SECRET_ACCESS_KEY="<secret_key>"

ExampleExample

In this example:

  1. A connection with Message Queue is established.
  2. A message queue is created with the mq_php_sdk_example name.
  3. A message with the text test-message is sent to the queue.
  4. The message is read from the queue and displayed in the terminal.
  5. The message queue is deleted.
<?php

use AsyncAws\Sqs\SqsClient;

require __DIR__ . '/vendor/autoload.php';


$mq = new SqsClient([
    'region' => 'ru-central1',
    'endpoint' => 'https://message-queue.api.cloud.yandex.net',
]);

$result = $mq->createQueue([
    'QueueName' => 'mq_php_sdk_example',
]);

$queueUrl = $result->getQueueUrl();
print('Queue created, URL: ' . $queueUrl . PHP_EOL);

$result = $mq->sendMessage([
    'QueueUrl' => $queueUrl,
    'MessageBody' => 'Test message',
]);

print("Message sent, ID: " . $result->getMessageId() . PHP_EOL);

$result = $mq->receiveMessage([
    'QueueUrl' => $queueUrl,
    'WaitTimeSeconds' => 10,
]);

foreach ($result->getMessages() as $msg) {
    print('Message received:' . PHP_EOL);
    print('ID: ' . $msg->getMessageId() . PHP_EOL);
    print('Body: ' . $msg->getBody() . PHP_EOL);

    $mq->deleteMessage([
        'QueueUrl' => $queueUrl,
        'ReceiptHandle' => $msg->getReceiptHandle(),
    ]);
}

$result = $mq->deleteQueue([
    'QueueUrl' => $queueUrl,
]);

print('Queue deleted' . PHP_EOL);

Was the article helpful?

Previous
Node.js
Next
Celery
© 2026 Direct Cursus Technology L.L.C.