Previously asked questions with same exception message did not solve my problem.
I have a consumer that is called from the command line, using the standard bundle cli command:
app/console rabbitmq:consumer -m 120 myproject_download
After consuming a few messages and performing the task as it should, it exits with the following exception:
[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] [--] <name>
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
Inside the consumer I also send a message to a new queue. Using the standard Symfony dependency injection. If I leave out sending this message, the following exception is shown, for the exact same procedure:
[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] [--] <name>
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
Starting the consumer again, has the same effect. A few messages are consumed and then it exits again.
In php.ini max_execution_time and max_input_time are a lot higher than the time it takes for the exception to occur.
And the Symfony config.yml looks like this:
# 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
What is going on? And how to stop it from exiting until all messages have been consumed?
I have had the same issue just now
Try change:
connection_timeout: 60
read_write_timeout: 60
# requires php-amqplib v2.4.1+ and PHP5.4+
keepalive: false
# requires php-amqplib v2.4.1+
heartbeat: 30
It works for me.
Here is the explanation about how to use this values: https://www.rabbitmq.com/heartbeats.html
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With