Likely causes
- •A web request is doing too much work. Imports, exports, report builds and bulk updates run inside one request. The stack trace in storage/logs/laravel.log points at a controller or a large loop, and the error appears only with bigger data sets.
- •Loading or looping over too many rows. Calls such as Model::all(), or queries inside a foreach (the N+1 pattern), make PHP hydrate and process thousands of models. The trace ends in Eloquent or a collection method, and a query debugger shows hundreds of queries for one request.
- •An infinite loop or runaway recursion after a code change. The error started right after a deploy, hits the same file and line every time, and happens even with a small amount of data. Raising the limit only delays the failure.
- •Slow work done synchronously in the request. Image resizing, PDF generation, and calls to slow third-party APIs all run while the user waits. The trace shows an image library, a PDF library or an HTTP client call.
- •The limit is too low for a legitimate long task. Migrations, backups or one-off maintenance run through a web route need more than 30 seconds. The same task finishes fine from the terminal, because the PHP CLI has no time limit by default.
- •You changed the wrong php.ini. You raised the limit but the web still fails at 30 seconds. The CLI and PHP-FPM read different files, so php -i may show your new value while PHP-FPM still uses the old one.
How to fix it
1. Find the script and line that timed out
Read the stack trace in the Laravel log. The first frame under the error shows the file and line where PHP was stopped. That tells you which of the causes applies. Run this from your Laravel project root.
grep -A 8 "Maximum execution time" storage/logs/laravel.log | tail -n 302. Check which limit the web process really uses
The CLI and PHP-FPM have separate settings. Replace 8.3 with your PHP version. On RHEL-family systems the binary is usually php-fpm with no version suffix. Look for the max_execution_time line in the output.
php -r 'echo ini_get("max_execution_time"), PHP_EOL;' php-fpm8.3 -i | grep max_execution_time # Ubuntu/Debian php-fpm -i | grep max_execution_time # RHEL, Rocky, Alma3. Fix the slow work first
Process large tables with chunkById() or cursor() instead of all(). Use eager loading (with()) to remove N+1 queries. Move long tasks such as exports and image processing into a queued job so the request returns at once. If the trace shows a loop that never ends, fix the code. A bigger limit will not help.
php artisan make:job ProcessExport4. Raise the limit for one script only
If one task legitimately needs more time, call set_time_limit(120) at the start of that controller method or command. This resets the timer and affects only that request, so the rest of the site keeps the safe default. Avoid set_time_limit(0) on web requests, because a stuck request then holds a PHP-FPM worker forever.
5. Raise the limit in php.ini for PHP-FPM (reloads PHP-FPM)
Use this only if many requests need it. The sed command keeps a .bak backup. A reload is graceful, but run it at a quiet moment. On Ubuntu/Debian the file is /etc/php/8.3/fpm/php.ini. On RHEL-family systems it is /etc/php.ini. For Apache with mod_php, edit /etc/php/8.3/apache2/php.ini and reload apache2 instead.
sudo sed -i.bak 's/^max_execution_time = .*/max_execution_time = 120/' /etc/php/8.3/fpm/php.ini sudo systemctl reload php8.3-fpm # RHEL: sudo systemctl reload php-fpm6. Match the web server and pool timeouts (reloads nginx)
If PHP now runs for 120 seconds but nginx gives up after its fastcgi_read_timeout (60 seconds by default), users get a 504 instead. Set fastcgi_read_timeout 120s; in the PHP location block of your site config. Also check request_terminate_timeout in your PHP-FPM pool file (/etc/php/8.3/fpm/pool.d/www.conf, or /etc/php-fpm.d/www.conf on RHEL), because it can kill a request regardless of max_execution_time. Test the config before reloading.
grep -rn "fastcgi_read_timeout" /etc/nginx/ sudo nginx -t && sudo systemctl reload nginx7. Set the timeout for queue workers and long artisan commands
Queue workers run on the CLI, so they use the --timeout flag, not max_execution_time. Keep retry_after in config/queue.php larger than the timeout, or jobs will be picked up twice. Restart the worker (or Supervisor program) after the change, which interrupts the job it is running.
php artisan queue:work --timeout=300 php -d max_execution_time=0 artisan your:command
Confirm it is fixed
Confirm PHP-FPM reports the new limit, then repeat the request that failed. The good output shows your new value in both columns, and no new 'Maximum execution time' lines appear in storage/logs/laravel.log.
php-fpm8.3 -i | grep max_execution_timeHow Opservo catches it early
The Opservo agent tails nginx, Apache, Laravel, Docker, PM2 and systemd journal logs and groups repeated lines into normalised patterns, so raw log lines are never stored. When this error keeps coming back, it raises a "recurring error" finding with a plain-English AI summary.
Last updated 2026-11-30.