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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 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 All @@ -34,6 +36,13 @@ class ServeCommand extends Command
*/
protected $description = 'Serve the application on the PHP development server';

/**
* The number of PHP CLI server workers.
*
* @var int<2, max>|false
*/
protected $phpServerWorkers = 1;

/**
* The current port offset.
*
Expand Down Expand Up @@ -76,14 +85,28 @@ 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',
];

/** {@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;
});

parent::initialize($input, $output);
}

/**
* Execute the console command.
*
Expand Down Expand Up @@ -154,7 +177,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 +383,7 @@ protected function flushOutputBuffer()
*/
protected function getDateFromLine($line)
{
$regex = ! windows_os() && env('PHP_CLI_SERVER_WORKERS', 1) > 1
$regex = ! windows_os() && is_int($this->phpServerWorkers)
? '/^\[\d+]\s\[([a-zA-Z0-9: ]+)\]/'
: '/^\[([^\]]+)\]/';

Expand Down
Loading