I'm just starting out with Laravel, going through my first tutorial, but I'm very curious about the timings that php artisan serve reports. They are either less than 1 ms, or consistently around 500ms, which is half a second.
The project itself is extremely simple, there are just a couple of routes, and the views return basically one html element. I'm running it on my own machine with Windows 10, a decently powerful CPU and an SSD. I have the project folder in Windows Defender exceptions.
The timings felt extremely bizarre, so I've decided to measure the performance in other ways. I've tried debugbar, telescope and I also wrote middleware that manually measures request timings. They all show completely normal values, there are no discrepancies between those three at all! I do know that the timings of php artisan serve are not exactly comparable to these ones, but I still expected to see a correlation, and there is none.
So what could this be? Is the timing tool itself broken somehow? I've tried doing php artisan serve in git bash and with cmd.exe as well.
Here's the example comparison of the same three requests in php artisan serve, in laravel.log and in telescope: (attached)
#Weird 500ms timings with php artisan serve
25 messages · Page 1 of 1 (latest)
php artisan serve uses the built in php web server which is not performant, it has its own performance overhead hence why the requests taking longer than what telescope is reporting. for the 1ms requests, those are fast because it's just file access and code execution is involved
whenever you switch to something like nginx or frankenphp in production(or developmwwnt env if you want) the requests will reflect close to what telescope is reporting since they are very performant
Telescope-reported timings using php artisan serve are close to irrelevant as mentioned above
if you are worried about performance caps, i recommend setting up some kind of environment (with docker or whatever you prefer) with php-fpm and nginx and redo your tests
you can (should) also use a profiler for this purpose
i know this isn't actually a big deal and it shouldn't affect things in a production-like environment. i'm just naturally curious and want to get to the bottom of things, i guess. and the reported timings being either sub 1ms or 500-515ms is very perplexing to me. there has never been a 2ms or 10ms or 400ms or 700ms timing
ok this continues not making any sense, things load more or less instantly for me, while it now started showing some completely made up, multisecond values
Have you tried this on WSL? I once experienced this issue while testing the framework on Windows, but after switching to WSL, it never happened again
i will definitely try it out a bit later after i finish the tutorial. these reported values are just smoke and mirrors, and they don't really affect me, it's mostly about my curiosity 🙂 thanks for the suggestion though
btw, php artisan serve is single-threaded. This means it can only handle one request at a time, so any subsequent requests will be hold until the current one is completed.
nope 😦
this is wsl and docker
wsl2 and native docker(not using docker desktop)?
I see you have installed telescope, can you share a screenshot of the telescope?
wsl2 yes and unfortunately i'm a little too noob to answer whether it's native docker or not
i do have docker desktop running
i must say that the app itself works super fast and these timings are the norm, they seem smaller than they were just on windows
right now i don't have telescope running, it's a brand new app. i finished that tutorial on windows and now started another one with wsl and docker 🙂
but every time when i looked at telescope with the previous app, i saw nothing out of the ordinary. these 500ms ones were only reported with php artisan serve, so built-in php server
laravel sail is using php artisan serve as well.
https://github.com/docker/for-win/issues/7719#issuecomment-749963371
you could follow the instruction here.
Just make sure you have the following things:
- wsl2
- docker desktop setting setup correctly.
It has a while since I coding at Window, hope the above reply could solve your case