Skip to content
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

add support to define write-timeout in ms #1517

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Monolog/Handler/SocketHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ private function writeToSocket(string $data): void

private function writingIsTimedOut(int $sent): bool
{
$writingTimeout = (int) floor($this->writingTimeout);
if (0 === $writingTimeout) {
// convert to ms
$writingTimeoutMs = $this->writingTimeout * 1000;
if (0 === $writingTimeoutMs) {
return false;
}

Expand All @@ -368,7 +369,10 @@ private function writingIsTimedOut(int $sent): bool
usleep(100);
}

if ((time() - $this->lastWritingAt) >= $writingTimeout) {
// convert to ms
$lastWritingMs = (time() - $this->lastWritingAt) * 1000;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this (and lastWritingAt) var should be based on microtime(true) and not time(). That'd make it more precise (because otherwise if you determine a write-timeout as 0.5, this code would anyway only timeout after a second has passed), and you would not have to multiply anything by 1000 anymore.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this myself in 3ee78ae


if ($lastWritingMs >= $writingTimeoutMs) {
$this->closeSocket();

return true;
Expand Down