diff --git a/src/Pdo/Queue.php b/src/Pdo/Queue.php index 9c0a305..5e8d395 100644 --- a/src/Pdo/Queue.php +++ b/src/Pdo/Queue.php @@ -111,7 +111,11 @@ public function consume(callable $callback, float $timeoutSecs): void $callback($this, $message); } - // Always process all the waiting responses + if (microtime(true) > $tsLimit) { + break; + } + + // If more queue items are pending, loop immediately if ($waitingReplies < 1) { $waitingReplies = $this->getMessageCount(); } @@ -119,9 +123,6 @@ public function consume(callable $callback, float $timeoutSecs): void continue; } - if (microtime(true) > $tsLimit) { - break; - } usleep(10); } } @@ -158,7 +159,7 @@ public function nack(QueueMessage $message): void */ public function getMessageCount(): ?int { - $sql = "SELECT COUNT(queueid) AS `c` + $sql = "SELECT COUNT(queueid) AS `c` FROM `q_{$this->name}` WHERE `locked` = 0 AND (`dt_scheduled` IS NULL OR `dt_scheduled` < NOW())"; @@ -172,7 +173,7 @@ public function getMessageCount(): ?int */ public function getTotalMessageCount(): ?int { - $sql = "SELECT COUNT(queueid) AS `c` + $sql = "SELECT COUNT(queueid) AS `c` FROM `q_{$this->name}` WHERE `locked` = 0"; $stmt = $this->pdo->query($sql); diff --git a/src/Pdo/ReplyQueue.php b/src/Pdo/ReplyQueue.php index 7ffaf1d..8d899ab 100644 --- a/src/Pdo/ReplyQueue.php +++ b/src/Pdo/ReplyQueue.php @@ -155,7 +155,11 @@ public function consume(callable $callback, float $timeoutSecs): void } } - // Always process all the waiting responses + if (microtime(true) > $tsLimit) { + break; + } + + // If more queue items are pending, loop immediately if ($waitingReplies < 1) { $waitingReplies = $this->getMessageCount(); } @@ -163,9 +167,6 @@ public function consume(callable $callback, float $timeoutSecs): void continue; } - if (microtime(true) > $tsLimit) { - break; - } usleep(10); } }