以前问过同样异常消息的问题并没有解决我的问题.
我有一个使用标准bundle cli命令从命令行调用的使用者:
app/console rabbitmq:consumer -m 120 myproject_download
在消耗了一些消息并按预期执行任务后,它将退出并出现以下异常:
[PhpAmqpLib\Exception\AMQPIOException] Error reading data. Received 0 instead of expected 1 bytes rabbitmq:consumer [-m|--messages [MESSAGES]] [-r|--route [ROUTE]] [-l|--memory-limit [MEMORY-LIMIT]] [-d|--debug] [-w|--without-signals] [--]PHP Fatal error: Uncaught exception 'PhpAmqpLib\Exception\AMQPIOException' with message 'Error reading data. Received 0 instead of expected 7 bytes' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:161 Stack trace: #0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\Wire\IO\StreamIO->read(7) #1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\Wire\AMQPReader->rawread(7) #2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\Wire\AMQPReader->read(7) #3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\Connection\AbstractConnection->wait_frame(0) #4 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(214): PhpAmqpLib\Connection\AbstractConnection->wait_channel(1, 0) #5 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Chan in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 161 Fatal error: Uncaught exception 'PhpAmqpLib\Exception\AMQPIOException' with message 'Error reading data. Received 0 instead of expected 7 bytes' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:161 Stack trace: #0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\Wire\IO\StreamIO->read(7) #1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\Wire\AMQPReader->rawread(7) #2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\Wire\AMQPReader->read(7) #3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\Connection\AbstractConnection->wait_frame(0) #4 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(214): PhpAmqpLib\Connection\AbstractConnection->wait_channel(1, 0) #5 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Chan in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 161
在消费者中,我还将消息发送到新队列.使用标准的Symfony依赖注入.如果我省略发送此消息,则会显示以下异常,对于完全相同的过程:
[PhpAmqpLib\Exception\AMQPRuntimeException] Broken pipe or closed connection rabbitmq:consumer [-m|--messages [MESSAGES]] [-r|--route [ROUTE]] [-l|--memory-limit [MEMORY-LIMIT]] [-d|--debug] [-w|--without-signals] [--]PHP Fatal error: Uncaught exception 'PhpAmqpLib\Exception\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190 Stack trace: #0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(336): PhpAmqpLib\Wire\IO\StreamIO->write('\x01\x00\x01\x00\x00\x00\v\x00\x14\x00(\x00\x00\x00\x00...') #1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(457): PhpAmqpLib\Connection\AbstractConnection->write('\x01\x00\x01\x00\x00\x00\v\x00\x14\x00(\x00\x00\x00\x00...') #2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(223): PhpAmqpLib\Connection\AbstractConnection->send_channel_method_frame(1, Array, Object(PhpAmqpLib\Wire\AMQPWriter)) #3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(170): PhpAmqpLib\Channel\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\Wire\A in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 190 Fatal error: Uncaught exception 'PhpAmqpLib\Exception\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190 Stack trace: #0 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(336): PhpAmqpLib\Wire\IO\StreamIO->write('\x01\x00\x01\x00\x00\x00\v\x00\x14\x00(\x00\x00\x00\x00...') #1 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(457): PhpAmqpLib\Connection\AbstractConnection->write('\x01\x00\x01\x00\x00\x00\v\x00\x14\x00(\x00\x00\x00\x00...') #2 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(223): PhpAmqpLib\Connection\AbstractConnection->send_channel_method_frame(1, Array, Object(PhpAmqpLib\Wire\AMQPWriter)) #3 /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(170): PhpAmqpLib\Channel\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\Wire\A in /var/www/html/my_project/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 190
再次启动消费者,具有相同的效果.消耗掉一些消息,然后再次退出.
在php.ini中,max_execution_time和max_input_time比发生异常所花费的时间高很多.
Symfony config.yml看起来像这样:
# rabbitmq old_sound_rabbit_mq: connections: default: host: '192.168.99.100' port: 5672 user: 'guest' password: 'guest' vhost: '/' lazy: false connection_timeout: 4 read_write_timeout: 4 # requires php-amqplib v2.4.1+ and PHP5.4+ keepalive: false # requires php-amqplib v2.4.1+ heartbeat: 2
到底是怎么回事?以及如何阻止它退出直到所有消息都被消费?