Maximum execution time exceeded
A fatal error: the script ran longer than max_execution_time. Find the slow part and move long work to a queue before you raise the limit.
- Message
- Maximum execution time of 30 seconds exceeded
What it means
PHP keeps a timer for every script and stops it once the timer passes max_execution_time. The default is 30 seconds, and 0 (no limit) when PHP runs from the command line. Like a memory error, this is a fatal error and not an exception: a catch (Throwable $e) around the slow code never runs.
Why it happens
- Something slow inside the request: a loop over thousands of records, building a large export or PDF, or a call to an external API that has no timeout of its own.
- Work that does not belong in a request at all, such as an import or sending mail to every user.
- The timer counts different things per platform. The PHP manual says that on systems other than Windows, time spent outside the script itself, in system calls, stream operations and database queries, does not count. On Windows the measured time is real time. Builds with
--enable-zend-max-execution-timers(the default for thread-safe builds on Linux and FreeBSD since PHP 8.3) also count elapsed time, sleeping and waiting included. On an Apple Silicon Mac, PHP uses a real-time timer as well:sleep(5)under a 2 second limit stopped after 2 seconds. So a slow query can trip the limit on your Mac and not on a Linux server with a standard build.
A web server timeout is a different error. When nginx stops waiting before PHP does, fastcgi_read_timeout (60 seconds by default) ends the request with a 504 Gateway Time-out, and PHP reports nothing. Apache's Timeout and PHP-FPM's request_terminate_timeout are two more limits outside PHP that can end a request.
How to fix it
Find the slow part first. Measure the step you suspect:
<?php
$start = hrtime(true);
$report = buildReport($customer);
error_log(sprintf('buildReport took %.0f ms', (hrtime(true) - $start) / 1e6));
Give every outgoing HTTP call a timeout, and fix slow queries with an index or a smaller result.
Move long work out of the request. In Laravel, dispatch a job and let a queue worker do it, or run it as an Artisan command, where the CLI default of 0 applies:
<?php
use App\Jobs\ExportOrders;
ExportOrders::dispatch($user);
return back()->with('status', 'Your export is being prepared.');
A queue worker has its own limit: queue:work stops a job after --timeout, 60 seconds by default. For a longer job, set public $timeout = 600; or #[Timeout(600)] on the job, and raise retry_after in config/queue.php above it, or another worker starts the job again.
Then, if the work really needs more time, raise the limit for that script. set_time_limit() restarts the timer from zero with the new value:
<?php
set_time_limit(120);
Or change it for every script in php.ini or the FPM pool:
max_execution_time = 60
A max_execution_time below nginx's timeout does not make PHP stop first: on Linux the timer skips the wait on a query or an API, so nginx can give up long before PHP's limit. Set timeouts on the outgoing calls and queries themselves. PHP-FPM's request_terminate_timeout does count wall-clock time, but it kills the worker, and Laravel logs nothing.
Find it in production
When PHP's limit fires, the visitor gets a 500. Laravel with APP_DEBUG=false shows its "Server Error" page; plain PHP with display_errors off sends an empty 500 and writes PHP Fatal error: Maximum execution time of 30 seconds exceeded to the PHP error log. Laravel reports it from its shutdown handler as Symfony\Component\ErrorHandler\Error\FatalError, with file and line, in storage/logs/laravel.log, so Ranetrace error monitoring records it with the request it happened on.
When nginx gives up first, the visitor gets a 504 and only the nginx error log knows: upstream timed out (110: Connection timed out) while reading response header from upstream. PHP keeps running until it finishes, and nothing reaches Laravel's log.
Reproduced on PHP 8.5, Laravel 13.45, 5 December 2026.
Related
Start monitoring today
Websites go down and code throws errors. Ranetrace tells you when it happens to yours, why it matters and what to do next.