Skip to content
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

[9.x] Fixes artisan serve command with PHP_CLI_SERVER_WORKERS environment variable #44204

Merged
merged 6 commits into from
Sep 19, 2022
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
21 changes: 20 additions & 1 deletion src/Illuminate/Foundation/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class ServeCommand extends Command
*/
protected $requestsPool;

/**
* Indicates if the "Server running on..." output message has been displayed.
*
* @var bool
*/
protected $serverRunningHasBeenDisplayed = false;

/**
* The environment variables that should be passed from host machine to the PHP server process.
*
Expand Down Expand Up @@ -106,6 +113,8 @@ public function handle()

$process->stop(5);

$this->serverRunningHasBeenDisplayed = false;

$process = $this->startProcess($hasEnvironment);
}

Expand Down Expand Up @@ -228,10 +237,16 @@ protected function handleProcessOutput()
{
return fn ($type, $buffer) => str($buffer)->explode("\n")->each(function ($line) {
if (str($line)->contains('Development Server (http')) {
if ($this->serverRunningHasBeenDisplayed) {
return;
}

$this->components->info("Server running on [http://{$this->host()}:{$this->port()}].");
$this->comment(' <fg=yellow;options=bold>Press Ctrl+C to stop the server</>');

$this->newLine();

$this->serverRunningHasBeenDisplayed = true;
} elseif (str($line)->contains(' Accepted')) {
$requestPort = $this->getRequestPortFromLine($line);

Expand Down Expand Up @@ -284,7 +299,11 @@ protected function handleProcessOutput()
*/
protected function getDateFromLine($line)
{
preg_match('/^\[([^\]]+)\]/', $line, $matches);
$regex = env('PHP_CLI_SERVER_WORKERS', 1) > 1
? '/^\[\d+]\s\[(.*)]/'
: '/^\[([^\]]+)\]/';

preg_match($regex, $line, $matches);

return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);
}
Expand Down