I have a simple PHP code that sends a message to a RabbitMQ queue, when I execute it directly from the console (#php script.php) the message is published correctly, but when I try to open the same script using my browser (http://localhost/script.php) the message is not sent. All previous lines are executed but the page stucks in the line
$connection = new AMQPConnection('$ipaddress', 5672, '$user', '$password');
Any ideas of why is this happening ?
CODE: script.php
<?php
include_once('rabbitmq_function.php');
$result = rabbitmq_send("test");
print_r($result);
CODE: rabbitmq_function.php
<?php
require_once '/usr/share/php/PhpAmqpLib/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
function rabbitmq_send($data)
{
print_r("Before AMQP Connection");
$connection = new AMQPConnection('10.0.0.8', 5672, 'guest', 'guest');
print_r("After AMQP Connection");
$channel = $connection->channel();
$channel->queue_declare('task_queue', false, true, false, false);
$msg = new AMQPMessage(
$data,
array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
);
$channel->basic_publish($msg, '', 'task_queue');
$channel->close();
$connection->close();
return true;
}
From CLI: I get the two debug messages (Before and After), and the return "1" value. And also I'm seeing a new message in the RabbitMQ management. From Browser: I get only printed the "Before AMQP Connection" message and no new message in the queue