5

I receive an error, when trying to receive answer from RabbitMQ.

2015-07-03 09:31:12 [10.1.101.55][-][-][error][PhpAmqpLib\Exception\AMQPTimeoutException] exception 'PhpAmqpLib\Exception\AMQPTimeoutException' with message 'The connection timed out after 30 sec while awaiting incoming data' in /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php:130
Stack trace:
#0 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(147): PhpAmqpLib\Wire\AMQPReader->wait()
#1 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(105): PhpAmqpLib\Wire\AMQPReader->rawread(7)
#2 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(528): PhpAmqpLib\Wire\AMQPReader->read(7)
#3 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(568): PhpAmqpLib\Connection\AbstractConnection->wait_frame(30)
#4 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(198): PhpAmqpLib\Connection\AbstractConnection->wait_channel(1, 30)
#5 /opt/www/site.ll/vendor/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(332): PhpAmqpLib\Channel\AbstractChannel->next_frame(30)

When I trying to receive answer from my local pc it works, but on production server - not.

Why, and how I can fix it.

Thanks!

user2264941
  • 407
  • 1
  • 8
  • 23
  • check if the ports for the MQ channels are not blocked or if the MQ service itself is running? – khakiout Jul 03 '15 at 09:07
  • It's running. AMQP receive my message, and process starting, but I dont receive answer. AMQP called callback function 42 times but there no my request. Then I receive exception. – user2264941 Jul 03 '15 at 09:12
  • On local PC I receive answer in 4 seconds. – user2264941 Jul 03 '15 at 09:15
  • If you can connect locally but not to remote servers, perhaps are you using the `guest` user account? See https://www.rabbitmq.com/access-control.html – old_sound Jul 05 '15 at 09:12
  • No, it's remote server. – user2264941 Jul 06 '15 at 07:42
  • Any solution did we found here ? – Sumeet Gohil Mar 20 '18 at 13:18
  • I'm getting this on Ubuntu... `PHP Fatal error: Uncaught PhpAmqpLib\Exception\AMQPTimeoutException: The connection timed out after 3 sec while awaiting incoming data in /home/website/PhpstormProjects/project/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php:132` – sdexp Jun 12 '18 at 09:26
  • For my case the timeout was due to me trying to connect to the wrong port. – sdexp Jun 12 '18 at 14:38

2 Answers2

9

Make sure the correct port is set. Default is 5672 (not 15672 which is web interface).

Gerard de Visser
  • 7,590
  • 9
  • 50
  • 58
  • 1
    This was the answer in my case. – tolga Mar 16 '22 at 15:02
  • What's the difference ? – biplab rout Sep 01 '22 at 07:54
  • 1
    The web interface is where you can login on RabbitMQ admin panel from browser, like: your-site.com: 15672. That's different from the port that the application needs to connect to the message server itself to publish, consume, etc. For this purpose port 5672 should be configured. – Gerard de Visser Sep 01 '22 at 08:01
2

The deafult timeouts for Connection, Read and Write is 3s. In the development, your requests process too faster than production, so you can't see this error message in the development.

If you need a greater timeout (as me), you can set it when you create an instance of AMQPStreamConnection:

$connection = new AMQPStreamConnection(
        'localhost',
        5672,
        'guest',
        'guest',
        '/',
        false,
        'AMQPLAIN',
        null,
        'en_US',
        30, //Connection Timeout
        30 // Read/Write Timeout
);

The above code set the Connection, Read and Write timeouts to 30s which is reasonable in my case.

Mostafa Lavaei
  • 1,960
  • 1
  • 18
  • 27