Hi all,
I made a very basic test API in Laravel which really only does 1 thing: returning the string ''hey''.
This is what it looks like in api.php:
Route::get('/test', function () { return 'Here!'; });
In Postman this API takes on average 200ms to execute.
I don't have years of Laravel experience, but even I know this seems very unacceptable. What could be causing API's to be this slow? There isn't even a database involved.
The project I've created is brand new and I haven't touched anything weird. I did a full cache refresh using php artisan optimize. The project is currently running on my local PHP webserver using php artisan serve. I also tried using 127.0.0.1 instead of localhost as some websites recommended but no difference. I'm also not using anything crazy like a docker or something.
@sr57 200ms for 1 string doesn't seem right? I mean what if I had a way bigger API like one that would return 100 users. How much time would that cost giving that it needs 200ms only to return the word ''here''.
@jlrdw I did a str_repeat('Name', 200). Don't know wether that would be good as well for testing purposes. This generates 1 big string with ''name'' being repeated 200 times. It takes around the same amount of time as only printing ''here''.
@jlrdw Fetxhing that same json directly from your github link in postman takes around 20ms. Copy/pasting the json data to Laravel and then returning that in the api takes again around 200ms in Postman.
200 does seem slow but of course i have no way of assessing the relative performance of your pc
The php webserver is in no way optimised for performance
what you appear to be missing is that booting the framework is thousands of lines of code so your one line of response is insignificant compared to booting the framework. You will find that the response is pretty constant irrespective of the complexity of your code