5

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?

1
  • my current fix is using supervisord to restart the workers automatically. And it works, but is a very ugly hack... I really hope someone can point me in the right direction! Commented Dec 8, 2015 at 17:10

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

you fixed my problem and will set as answer, but why did it fix it? I read the documentation, but to no avail. I had timeouts and heartbeat in the same ratio as your fix. Any idea why it needs these greater values?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.