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

joshuaziering's avatar

Extremely Slow Requests In Production But Fast On Dev?

I built a new server on Laravel Forge. I removed php 7 and put in 5.6.

I have an API endpoint that returns a HasMany relationship. In Dev, with a copy of the production database, on my Macbook Pro the underlying query returns in ~1.8ms. The total processing time for the method is ~.50 seconds using $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];

In production it takes about 20seconds(!!!) for this same call to return. In our crummy staging server it only takes 2.

What's causing such a drastic slowdown? I know it's not the query or the method.

Ubuntu 16 Nginx PHP-Fpm 5.6 (Stock configuration)

What do I need to do to speed this up? Where should I look?

0 likes
5 replies
TheNodi's avatar

@joshuaziering

Have you checked CPU and network load on the production server?

Blackfire might help you out. You can profile single requests on production server (never tried, but it's written in the site).

aardalich's avatar

Did you use ->index() on all the columns you're using in your query to get those columns indexed by the database?

Might pay to look at the database structure on production and make sure it created all the indexes you specified in your migrations.

joshuaziering's avatar

I went ahead and did toSql() and ran the exact query in production and dev. The query takes less than 100ms in both.

joshuaziering's avatar

I restarted the server and now it's down to like 2.5 seconds. Not sure what was going on.

bashy's avatar

Whenever you get a hang like that, it's always a resource waiting on another to complete. Sounds like you just freed up whatever it was. Be careful it doesn't come back if you don't find out what it was.

Common things are;

  • Mail delay
  • Logging from mysql/fpm/nginx/apache etc
  • Hostname look ups (also DNS)
  • File reading wait time
1 like

Please or to participate in this conversation.