8000 Reset the last ping time only after a ping is sent, rather than after… by bgreco · Pull Request #5 · php-mqtt/client · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Reset the last ping time only after a ping is sent, rather than after… #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
7 changes: 4 additions & 3 deletions src/MQTTClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ protected function performConnectionHandshake(string $username = null, string $p
switch ($acknowledgement[3]) {
case chr(0):
$this->logger->info(sprintf('Connection with MQTT broker at [%s:%s] established successfully.', $this->host, $this->port));
$this->lastPingAt = microtime(true);
break;
case chr(1):
$this->logger->error(sprintf('The MQTT broker at [%s:%s] does not support MQTT v3.', $this->host, $this->port));
Expand Down Expand Up @@ -653,8 +652,6 @@ public function loop(bool $allowSleep = true, bool $exitWhenQueuesEmpty = false,
$this->logger->debug(sprintf('Received message with unsupported command [%s]. Skipping.', $command));
break;
}

$this->lastPingAt = microtime(true);
} else {
$this->logger->error('A reserved command has been received from an MQTT broker. Supported are commands (including) 1-14.', [
'broker' => sprintf('%s:%s', $this->host, $this->port),
Expand Down Expand Up @@ -1304,6 +1301,10 @@ protected function writeToSocket(string $data, int $length = null): void
]);
throw new DataTransferException(self::EXCEPTION_TX_DATA, 'Sending data over the socket failed. Has it been closed?');
}

// After writing successfully to the socket, the broker should have received a new message from us.
// Because we only need to send a ping if no other messages are delivered, we can safely reset the ping timer.
$this->lastPingAt = microtime(true);
}

/**
Expand Down
0