Skip to content

Conversation

nunomaduro
Copy link
Member

This pull request improves Laravel's serve artisan command. Here is the difference:

Screenshot 2022-07-22 at 18 32 56

So, the output got improved. The "time" is the only information highlighted, as is the only thing that actually changes. And we got to see a "rounded" duration of the request.

Note that, because we are using PHP's built-in server using a file such as "server.php", we don't have information regarding the Method, Uri, Response Code, etc.

In addition, unexpected output such as port already in use, or .env got changed, is displayed this way:

Screenshot 2022-07-22 at 18 00 50

Screenshot 2022-07-22 at 18 01 53

@nunomaduro nunomaduro requested a review from taylorotwell July 22, 2022 17:35
@taylorotwell taylorotwell merged commit a52f623 into 9.x Jul 25, 2022
@taylorotwell taylorotwell deleted the feat/improve-serve-command branch July 25, 2022 14:32
@antonkomarev
Copy link
Contributor

@nunomaduro new implementation missing PHP version. Not sure it's really important, but may be useful in some edge cases.

@nunomaduro
Copy link
Member Author

It's intentional.

@RosiersRobin
Copy link

RosiersRobin commented Jul 26, 2022

I'm getting an error serving from specific port and host. I think this can be resolved by putting an isset around the array of matches.

ErrorException Undefined array key 1313 at \vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:250 246▕ $this->requestsPool[$matches[1]][1] = trim(explode('[200]: GET', $line)[1]); 247▕ } elseif (str($line)->contains(' Closing')) { 248▕ preg_match('/\:(\d+)/', $parts[1], $matches); 249▕ ➜ 250▕ $request = $this->requestsPool[$matches[1]]; 251▕ 252▕ [$startDate, $file] = $request; 253▕ $formattedStartedAt = $startDate->format('Y-m-d H:i:s'); 254▕ 1 \vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:250 Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("Undefined array key 1313", "\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php") 2 \vendor\laravel\framework\src\Illuminate\Collections\Traits\EnumeratesValues.php:264 Illuminate\Foundation\Console\ServeCommand::Illuminate\Foundation\Console\{closure}("[Tue Jul 26 17:26:27 2022] 127.0.0.1:1313 Closing ") 

This occures when running serve this way: php artisan serve --port 80 --host 0.0.0.0

and accessing the served site via http://development.docker/.

@ankurk91
Copy link
Contributor

Rather than showing ~0 seconds, can we show milliseconds?

@nunomaduro
Copy link
Member Author

@ankurk91 It's not possible due PHP Built-in server limitations.

Ken-vdE pushed a commit to Ken-vdE/framework that referenced this pull request Aug 9, 2022
* Improves `serve` Artisan command * Handles better edge cases * Removes assets requests, and displays unexpected output as "warn" * Simplifies command and handles assets * Better captures * formatting Co-authored-by: Taylor Otwell <taylor@laravel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants