Skip to content

Commit

Permalink
empty result processing 1ms delay
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Jan 21, 2022
1 parent ba88662 commit 694bb04
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,14 @@ public function setTimeout(float $value): self

public function process(null|int|float $timeout = 0)
{
$start = microtime(true);
$max = microtime(true) + $timeout;

while (!($line = stream_get_line($this->socket, 1024, "\r\n"))) {
if (microtime(true) - $start > $timeout) {
if (microtime(true) > $max) {
return null;
}
// 1ms sleep
usleep(1_000);
}

switch (trim($line)) {
Expand Down

0 comments on commit 694bb04

Please sign in to comment.