From 1822b6de29a50d3f7167816428a57d55d1e09cf2 Mon Sep 17 00:00:00 2001 From: Rui Campos Date: Mon, 13 Jul 2015 16:54:21 +0100 Subject: [PATCH] Heartbeat frames will decrease the timeout used when calling wait_channel - heartbeat frames do not reset the timeout --- PhpAmqpLib/Connection/AbstractConnection.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/PhpAmqpLib/Connection/AbstractConnection.php b/PhpAmqpLib/Connection/AbstractConnection.php index d2dfe00e2..362d4b7c9 100644 --- a/PhpAmqpLib/Connection/AbstractConnection.php +++ b/PhpAmqpLib/Connection/AbstractConnection.php @@ -564,11 +564,23 @@ protected function wait_frame($timeout = 0) */ protected function wait_channel($channel_id, $timeout = 0) { + // Keeping the original timeout unchanged. + $_timeout = $timeout; while (true) { - list($frame_type, $frame_channel, $payload) = $this->wait_frame($timeout); + $now = time(); + list($frame_type, $frame_channel, $payload) = $this->wait_frame($_timeout); if ($frame_channel === 0 && $frame_type === 8) { - // skip heartbeat frames + // skip heartbeat frames and reduce the timeout by the time passed + if( $_timeout > 0 ) + { + $_timeout -= time() - $now; + if( $_timeout <= 0 ) + { + // If timeout has reached, throw the exception without calling wait_frame + throw new AMQPTimeoutException( "Timeout waiting on channel"); + } + } continue; } else {