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

nmp4817's avatar

Why Laravel Empty Api endpoints taking 1.5 seconds

Why my simple API call with no queries and no data takes ~1.5 seconds?

I cached routes, config and ran php artisan optimize

I tried looking in the timeline of the request in https://github.com/itsgoingd/clockwork it shows the total time of 1589 ms. The controller takes 87ms. (Weird thing is I don't even controller)

I am just returning an empty array from routes/api.php

Can someone shed some light on what could be going on?

I am using postman to test.

Thanks

0 likes
16 replies
sr57's avatar

What's your config/platform?

nmp4817's avatar

I am not sure what do you mean by config/platform?

But I am using Laravel. Implementing Rest API application

sr57's avatar

what's your server : linux, window, sail, ...?

what's your db and how large is your table?

Tray2's avatar

What do you do in the endpoint?

Without knowing anything about what you are trying to do, it's impossible to guess.

However usually if something takes time it's most likely the query of the database that are missing some indexes.

rognales's avatar

What's your setup? Served by artisan serve?

CorvS's avatar

Are any (weird) middlewares registered for your API routes inside your App\Http\Kernel or App\Providers\RouteServiceProvider that query your database? Did you try creating a fresh Laravel app to see if the problem is related to your specific app?

nmp4817's avatar

Yeah I tried commenting on all the middlewares but it did not make any changes

I have Laravel Telescope installed, which I did not comment on. Do you think that would add some delay?

But good point about checking with fresh Laravel app Let me try that.

thanks.

automica's avatar

Telescope will add an overhead to your app and is your likely cause.

CorvS's avatar

That depends, is your database inside another Docker container? Is database access slow in general? Which watchers did you register?

nmp4817's avatar

Hi, thanks y'all for responding,

It turns out docker was the issue not sure what was the reason I am still figuring out why it's slow

@corvs

  • database is outside docker
  • I have only a couple of watchers on for telescope
  • database is super quick I checked using a telescope and clockwork, queries were pretty quick

any idea why using docker is slowing it down?

Thanks

CorvS's avatar

Did you limit the container's resources maybe? Like memory or CPU?

nmp4817's avatar

Yes I think that was the issue I haven't increased it and ran it but will definitely check

thanks

walidaalhomsi's avatar

@nmp4817 how did you resolve this issue? Having almost the same thing here, empty route takes 0.5 second ...

Please or to participate in this conversation.