diff --git a/src/Illuminate/Foundation/Console/ServeCommand.php b/src/Illuminate/Foundation/Console/ServeCommand.php index c4b32b6d4004..0f863f1407c8 100644 --- a/src/Illuminate/Foundation/Console/ServeCommand.php +++ b/src/Illuminate/Foundation/Console/ServeCommand.php @@ -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. * @@ -106,6 +113,8 @@ public function handle() $process->stop(5); + $this->serverRunningHasBeenDisplayed = false; + $process = $this->startProcess($hasEnvironment); } @@ -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(' Press Ctrl+C to stop the server'); $this->newLine(); + + $this->serverRunningHasBeenDisplayed = true; } elseif (str($line)->contains(' Accepted')) { $requestPort = $this->getRequestPortFromLine($line); @@ -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]); }