好的,这是 Symfony2 命令行脚本的一部分。在脚本等待时,它会因此异常而死亡。
[PhpAmqpLib\Exception\AMQPRuntimeException]
Error reading data. Received 0 instead of expected 1 bytes
我搜索了谷歌,发现提到了 heartbeat 和 set_time_out,但是当我尝试在构造函数中设置时,但是当我从默认值更改它时,它死得更快。
这就是我的脚本的设置方式。对于它的 Amqplib 方面。
// Get the configuration options for RabbitMQ
$queueConfig = $this->getApplication()->getKernel()->getContainer()->getParameter("rabbit_mq");
/**
* Callback function for RabbitMQ
* Everything in the callback function must remain in the call back function.
*/
$callback = function($msg)
{
$msgObj = json_decode($msg->body, true);
print_r($msgObj);
};
$connection = new AMQPConnection(
$queueConfig['response']['host'],
$queueConfig['response']['port'],
$queueConfig['response']['username'],
$queueConfig['response']['password'],
'/'
);
$channel = $connection->channel();
$queueName = 'myQueueName';
$channel->basic_consume($queueName, '', false, true, false, false, $callback);
while(count($channel->callbacks)) {
$channel->wait();
}
这来自具有构造函数的 AMQPStreamConnection.php。AMQPConnection 扩展 AMQPStreamConnection
public function __construct($host, $port,
$user, $password,
$vhost="/",$insist=false,
$login_method="AMQPLAIN",
$login_response=null,
$locale="en_US",
$connection_timeout = 3,
$read_write_timeout = 3,
$context = null)
关于如何摆脱错误的想法?