CloudAMQP and php

Hi I’m new to Rabbitmq and I’m running some tests, I’ve managed to install and run it on localhost but now I would like to use the cloud server from cloudamqp, so I’ve used the following code:

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Connection\AMQPSSLConnection;
use PhpAmqpLib\Message\AMQPMessage;
$url = parse_url(getenv('CLOUDAMQP_URL'));
$vhost = substr($url['path'], 1);
if($url['scheme'] === "amqps") {
    $ssl_opts = array(
        'capath' => '/etc/ssl/certs'
    $conn = new AMQPSSLConnection($url['host'], 5671, $url['user'], $url['pass'], $vhost, $ssl_opts);    
} else {
    $conn = new AMQPStreamConnection($url['host'], 5672, $url['user'], $url['pass'], $vhost);    
$ch = $conn->channel();
$exchange = '';
$queue = 'basic_get_queue';
$ch->queue_declare($queue, false, true, false, false);
$ch->exchange_declare($exchange, 'direct', true, true, false);
$ch->queue_bind($queue, $exchange);
$msg_body = 'the body';
$msg = new AMQPMessage($msg_body, array('content_type' => 'text/plain', 'delivery_mode' => 2));
echo "Sending message...\n";
$ch->basic_publish($msg, $exchange);
$retrived_msg = $ch->basic_get($queue);
echo sprintf("Message recieved: %s\n", $retrived_msg->body);

I’ve replaced CLOUDAMQP_URL with my url amqp:// and when I run the php file I get

Fatal error: Uncaught ErrorException: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
Clearly I’m doing something wrong, can anybody ppint me to the right direction? Many thanks


$url = parse_url(getenv('CLOUDAMQP_URL'));

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.