From 3aae0fd3e8d2fdd1a42112532dcfbb453439fae9 Mon Sep 17 00:00:00 2001 From: Michael Calcinai Date: Wed, 2 Dec 2015 10:14:01 +1300 Subject: [PATCH] Fix heartbeat --- src/Protocol/AbstractProtocol.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Protocol/AbstractProtocol.php b/src/Protocol/AbstractProtocol.php index 95f2285..0a05385 100644 --- a/src/Protocol/AbstractProtocol.php +++ b/src/Protocol/AbstractProtocol.php @@ -59,14 +59,15 @@ public function onHeartbeat(){ $this->heartbeat_timer->cancel(); } - //Set a new timeout (1 sec seems reasonable) - $this->heartbeat_timer = $this->client->getLoop()->addTimer(2, function(){ - $this->stream->close(); - throw new ConnectionLostException(); - }); - $this->client->getLoop()->addTimer($this->client->getHeartbeatInterval(), function(){ + //Set a new timeout (1 sec seems reasonable) + $this->heartbeat_timer = $this->client->getLoop()->addTimer(2, function(){ + $this->stream->close(); + throw new ConnectionLostException(); + }); + $this->sendHeartbeat(); + }); }