Why Raising max_execution_time Didn't Fix Your PHP Error
You raised max_execution_time from 30 to 300 seconds, deployed, clicked the button again — and the same error came back. If that sounds familiar, the PHP time limit was never your problem. It was just the first suspect.
Here is the mistake: a PHP request does not have one timeout. It has a stack of them, and the shortest one wins. Until you find out which clock actually stopped the request, every fix is a guess.
The limit that lies to you
On Linux, max_execution_time only counts the time PHP itself spends running code. Waiting does not count — not a slow database query, not a hanging API call, not sleep(). So when a script dies at exactly 30 seconds, it did 30 seconds of actual PHP work. That points at a loop that never ends, or a request doing far too much at once — not at a limit that is too low.
And the line number in the error message is where PHP happened to be when the timer expired, not where the slowness lives. A loop running a million times gets reported on whatever line it was executing at second 30.
The other clocks
Match what you saw, and you will know where to look:
- PHP fatal at exactly the limit — PHP stopped it. Check the PHP or Laravel log.
- 504 Gateway Time-out, often at exactly 60 seconds — nginx stopped waiting. The nginx error log says
upstream timed out, and the fix isfastcgi_read_timeout, notphp.ini. - 502 Bad Gateway — PHP-FPM killed the worker. The FPM log says
execution timed out, and the pool settingrequest_terminate_timeoutis the cause. - Queue job failed, worker exit code 137 — the Laravel worker's
--timeoutkilled it.
Fix the work, then the limit
The durable fix is almost always in the code. Close the runaway loop. Replace the N+1 query pattern with eager loading and chunk() so an export processes 500 rows at a time instead of loading a whole table. Move imports and bulk jobs that genuinely take minutes into a queue or a cron script, where the web time limit does not apply at all.
Only when the work is genuinely large should you raise the limit — narrowly, for that one script, with set_time_limit(300) at the top of it. Raising it for the whole site just lets the next broken script hold a worker for five minutes instead of thirty.
The full step-by-step guide, with the reproduction commands, the diagnosis table, and every timer set correctly, is here:
https://rajadevsolutions.online/errors/how-to-fix-maximum-execution-time-exceeded-error-in-php
About the author
- Full Stack Developer — PHP, Laravel, MySQL, JavaScript. I write practical coding solutions at rajadevsolutions.online
Comments
Join the discussionNo comments yet. Be the first to comment.