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

Atef95's avatar

Very slow response...

Hi Artisans

I've a query in my project that runs within 112ms in the dev environnement (with the same exact amount of data as on production )..

On production server it takes 7.28s ( TTFB)..

what causes that ?

is it from the web server ?

Thank you

0 likes
3 replies
Tray2's avatar

What kind of environment do you have on the production server? Are you hitting the database? Is the database on the same server or a remote one? Do you have large images?

Atef95's avatar

1 - Ubuntu Vps

2 - Yes

3 - same server

4 - No

I think the issue is from the query..

because I tried to remove the query and the page loaded quickly ( so it's an issue from the application not the server)

I don't know why there is no issues in my local dev ..

That's my query..

      $zones = Zone::withCount([

            'trashes' => function ($query) {
                $query->whereDoesntHave('pointings', function ($queryPointings) {
                    $queryPointings->whereMonth('created_at', Carbon::now()->month);
                });

            }])
            ->having('trashes_count', '>', 0)
            ->get();
     

I added an index on created_at field from pointings table but no way..

I also have an index on zone_id field from trashes table..

Tray2's avatar

If you change the ->get() to ->toSQL() and then run the query generated in a database tool like tableplus or similar after adding the keyword explain in front of it.

explain select id from some_table;

Then show both the query and the resulting plan.

Please or to participate in this conversation.