When I run my program through command line, then my PHP script works fine and gives output properly.
But when I run it through my browser, then it processes fine but the output I printed - is not showing.
( Note : My script is running in a while loop and it will run forever )
Code - I am writing some part of my class file
public function call($n) {
global $argv;
$this->response = null;
$this->corr_id = uniqid();
$msgBody = 'test msg';
//Create queue
$this->createQueue($queueName);
$msg = new AMQPMessage(
(string) $msg_body,
array('correlation_id' => $this->corr_id,
'reply_to' => $this->callback_queue,
'priority' => 2)
);
$this->channel->basic_publish($msg, '', $queueName);
while(!$this->response) {
$this->channel->wait();
}
return $this->response;
}
$response = call();
createQueue() function is in another class
function createQueue($queueName='')
{
$exchange = 'router';
$queue = 'msgs';
$consumer_tag = 'consumer';
$connection = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$channel = $connection->channel();
$channel->queue_declare($queueName, false, false, false, false);
echo " [x] Awaiting for message\n";
$callback = function($req) {
$n = $req->body;
echo "$n\n";
$msg = new AMQPMessage(
'msg',
array('correlation_id' => $req->get('correlation_id'))
);
$req->delivery_info['channel']->basic_publish(
$msg, '', $req->get('reply_to'));
$req->delivery_info['channel']->basic_ack(
$req->delivery_info['delivery_tag']);
};
$channel->basic_qos(null, 1, null);
$channel->basic_consume($queueName, '', false, false, false, false, $callback);
while(count($channel->callbacks)) {
$channel->wait();
}
}