-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed as duplicate of#18304
Labels
Description
Description
With the latest Laravel 11 (version 11.44.2), the following code:
The script crash with sleep function.
<?php
/code$ php artisan tinker
Psy Shell v0.12.8 (PHP 8.3.20 — cli) by Justin Hileman
> \Illuminate\Support\Sleep::sleep(1); 1;
/code$ While native sleep is working.
<?php
text_product_v2:/code$ php artisan tinker
Psy Shell v0.12.8 (PHP 8.3.20 — cli) by Justin Hileman
> sleep(1); 1
= 1
> The code that crash is here in the destruction function
/**
* Handle the object's destruction.
*
* @return void
*/
public function __destruct()
{
$this->goodnight();
}
/**
* Handle the object's destruction.
*
* @return void
*/
protected function goodnight()
{
if ($this->alreadySlept || ! $this->shouldSleep) {
return;
}
if ($this->pending !== null) {
throw new RuntimeException('Unknown duration unit.');
}
if (static::$fake) {
static::$sequence[] = $this->duration;
if (static::$syncWithCarbon) {
Carbon::setTestNow(Carbon::now()->add($this->duration));
}
foreach (static::$fakeSleepCallbacks as $callback) {
$callback($this->duration);
}
return;
}
$remaining = $this->duration->copy();
$seconds = (int) $remaining->totalSeconds;
$while = $this->while ?: function () {
static $return = [true, false];
return array_shift($return);
};
while ($while()) {
if ($seconds > 0) {
sleep($seconds);
$remaining = $remaining->subSeconds($seconds);
}
$microseconds = (int) $remaining->totalMicroseconds;
if ($microseconds > 0) {
usleep($microseconds);
}
}
}I can reproduce it in my code too. I used tinker here to simplify steps to reproduce.
This was working with previous version of Php (8.3.19)
See also laravel/framework#55437
PHP Version
PHP 8.3.20 (cli) (built: Apr 11 2025 17:02:45) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.20, Copyright (c) Zend Technologies
with Zend OPcache v8.3.20, Copyright (c), by Zend Technologies
Operating System
Alpine with kernel 6.8.0-57-generic