Skip to content

[11.x] Fix serve command with PHP_CLI_SERVER_WORKERS #54606

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

Merged
merged 10 commits into from
Feb 17, 2025
27 changes: 24 additions & 3 deletions src/Illuminate/Foundation/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use Illuminate\Support\InteractsWithTime;
use Illuminate\Support\Stringable;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

use function Illuminate\Support\php_binary;
Expand Down Expand Up @@ -76,14 +78,33 @@ class ServeCommand extends Command
'IGNITION_LOCAL_SITES_PATH',
'LARAVEL_SAIL',
'PATH',
'PHP_CLI_SERVER_WORKERS',
'PHP_IDE_CONFIG',
'SYSTEMROOT',
'XDEBUG_CONFIG',
'XDEBUG_MODE',
'XDEBUG_SESSION',
];

/**
* The number of PHP_CLI_SERVER_WORKERS.
*
* @var int|false
*/
protected $phpServerWorkers = 1;

/** {@inheritdoc} */
#[\Override]
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->phpServerWorkers = transform(env('PHP_CLI_SERVER_WORKERS', 1), function ($workers) {
if (! is_int($workers) || $workers < 2) {
return false;
}

return $workers > 1 && ! $this->option('no-reload') ? false : $workers;
});
}

/**
* Execute the console command.
*
Expand Down Expand Up @@ -154,7 +175,7 @@ protected function startProcess($hasEnvironment)
}

return in_array($key, static::$passthroughVariables) ? [$key => $value] : [$key => false];
})->all());
})->merge(['PHP_CLI_SERVER_WORKERS' => $this->phpServerWorkers])->all());

$this->trap(fn () => [SIGTERM, SIGINT, SIGHUP, SIGUSR1, SIGUSR2, SIGQUIT], function ($signal) use ($process) {
if ($process->isRunning()) {
Expand Down Expand Up @@ -360,7 +381,7 @@ protected function flushOutputBuffer()
*/
protected function getDateFromLine($line)
{
$regex = ! windows_os() && env('PHP_CLI_SERVER_WORKERS', 1) > 1
$regex = ! windows_os() && $this->phpServerWorkers > 1
? '/^\[\d+]\s\[([a-zA-Z0-9: ]+)\]/'
: '/^\[([^\]]+)\]/';

Expand Down
Loading