Skip to content

Commit 2824d43

Browse files
committed
$sleep as a float to support parts of seconds
1 parent e018622 commit 2824d43

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/CLI/Console.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,15 @@ static public function isInteractive(): bool
189189

190190
/**
191191
* @param callable $callback
192-
* @param int $sleep // seconds
192+
* @param float $sleep // in seconds!
193193
* @param callable $onError
194-
* @throws \Exception
195194
*/
196-
static public function loop(callable $callback, int $sleep = 1 /* 1 second */, callable $onError = null): void
195+
static public function loop(callable $callback, $sleep = 1 /* seconds */, callable $onError = null): void
197196
{
198197
gc_enable();
199198

200199
$time = 0;
201-
200+
202201
while (!connection_aborted() || PHP_SAPI == "cli") {
203202
try {
204203
$callback();
@@ -210,12 +209,12 @@ static public function loop(callable $callback, int $sleep = 1 /* 1 second */, c
210209
}
211210
}
212211

213-
sleep($sleep);
212+
usleep($sleep * 1000000);
214213

215214
$time = $time + $sleep;
216215

217216
if (PHP_SAPI == "cli") {
218-
if($time >= (5 * 60)) { // Every 5 minutes
217+
if($time >= $time * 60 * 5) { // Every 5 minutes
219218
$time = 0;
220219
gc_collect_cycles(); //Forces collection of any existing garbage cycles
221220
}

0 commit comments

Comments
 (0)