diff --git a/src/Bunny/Client.php b/src/Bunny/Client.php index 1ea5503..c059963 100644 --- a/src/Bunny/Client.php +++ b/src/Bunny/Client.php @@ -189,7 +189,10 @@ public function run($maxSeconds = null) } else { if (($frame = $this->reader->consumeFrame($this->readBuffer)) === null) { $now = microtime(true); - $nextStreamSelectTimeout = $nextHeartbeat = ($this->lastWrite ?: $now) + $this->options["heartbeat"]; + $nextStreamSelectTimeout = ($this->lastWrite ?: $now) + $this->options["heartbeat"]; + if (!isset($nextHeartbeat)) { + $nextHeartbeat = $now + $this->options["heartbeat"]; + } if ($stopTime !== null && $stopTime < $nextStreamSelectTimeout) { $nextStreamSelectTimeout = $stopTime; } @@ -224,6 +227,7 @@ public function run($maxSeconds = null) $now = microtime(true); if ($now >= $nextHeartbeat) { + $nextHeartbeat = $now + $this->options["heartbeat"]; $this->writer->appendFrame(new HeartbeatFrame(), $this->writeBuffer); $this->flushWriteBuffer();