Skip to content

Commit

Permalink
Simplify timeout handling and really allow millisecond precision, refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Dec 14, 2020
1 parent 1850160 commit 3ee78ae
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/Monolog/Handler/SocketHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SocketHandler extends AbstractProcessingHandler
private $persistent = false;
private $errno;
private $errstr;
/** @var ?float */
private $lastWritingAt;

/**
Expand Down Expand Up @@ -355,24 +356,20 @@ private function writeToSocket(string $data): void
private function writingIsTimedOut(int $sent): bool
{
// convert to ms
$writingTimeoutMs = $this->writingTimeout * 1000;
if (0 === $writingTimeoutMs) {
if (0 === $this->writingTimeout) {
return false;
}

if ($sent !== $this->lastSentBytes) {
$this->lastWritingAt = time();
$this->lastWritingAt = microtime(true);
$this->lastSentBytes = $sent;

return false;
} else {
usleep(100);
}

// convert to ms
$lastWritingMs = (time() - $this->lastWritingAt) * 1000;

if ($lastWritingMs >= $writingTimeoutMs) {
if ((microtime(true) - $this->lastWritingAt) >= $this->writingTimeout) {
$this->closeSocket();

return true;
Expand Down

0 comments on commit 3ee78ae

Please sign in to comment.