Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Toufik94's avatar

Basic Laravel API pretty slow

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.

0 likes
13 replies
Toufik94's avatar

@martinbean 200ms for just 1 simple string doesn't seem right to me. The least I would expect is a response time below 100ms.

jlrdw's avatar

@Toufik94 remember tracking it with a debug tool in order to time it can actually increase the time.

2 likes
Toufik94's avatar

@jlrdw I don't use a debugtool to track its time. In Postman you can see exactly how much time it took to fetch the API. It says around 200ms.

sr57's avatar

@toufik94

What do you measure with postman ?

How do you measure with postman and "php artisan serve" ?

Best way, open firefox dev tools / network and see the elapsed time for your request.

2 likes
Toufik94's avatar

@sr57 In Firefox it also says that it takes around 200ms to fetch the API. That can't be right

sr57's avatar

@Toufik94

It's right but it seems too long really, anything in your logs?

Toufik94's avatar

@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''.

Or am I judging this completely wrong?

jlrdw's avatar

@Toufik94 return a json array with 200 names, how long? I am guessing it will be about the same.

2 likes
Toufik94's avatar

@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''.

Toufik94's avatar

@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.

Thats almost 10 times as slow.

Snapey's avatar

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

2 likes

Please or to participate in this conversation.