docs
docs copied to clipboard
Add PHP to AMQP tutorial
For a support issue, I put together a subscriber for our queues for PHP. We should make use of it and add it to the existing AMQP tutorials
Code:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPSSLConnection;
$ssl_options = array(
'capath' => '/etc/ssl/certs'
);
$connection = new AMQPSSLConnection(
'us-east-1-a-queue.ably.io',
5671,
'FIRST_HALF_API_KEY_HERE',
'SECOND_PART_API_KEY_HERE,
'shared',
$ssl_options);
function process_message($message)
{
echo "\n--------\n";
echo $message->body;
echo "\n--------\n";
$message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);
// Send a message with the string "quit" to cancel the consumer.
if ($message->body === 'quit') {
$message->delivery_info['channel']->basic_cancel($message->delivery_info['consumer_tag']);
}
}
$channel = $connection->channel();
$channel->basic_consume('APP_ID:YOUR_QUEUE_NAME, '', false, false, false, false, 'process_message');
while (count($channel->callbacks)) {
$channel->wait();
}
$channel->close();
$connection->close();
?>