Knowledge

PHP Maximum execution time of N seconds exceeded

#PHP

This fatal error means a PHP script ran longer than the allowed time limit and was killed. Raise the limit for legitimately long work, but the real fix is usually to make the script faster or move it to a queue.

Published by Mark van Eijk on June 23, 2026 · 1 minute read

  1. About the error
  2. Why do I see this error
  3. Solution
  4. Raise the limit
  5. The real fix: don't do slow work in a request

About the error

PHP Fatal error: Maximum execution time of 30 seconds exceeded

PHP caps how long a single script may run with the max_execution_time setting (default 30 seconds for web requests). When a script exceeds it, PHP terminates it mid-run, which usually surfaces as a 500 error or a half-rendered page.

Why do I see this error

  • A slow database query, often a missing index.
  • Heavy work done inside a web request: large exports, image processing, sending many emails.
  • A slow or hanging external API call.
  • An accidental infinite loop.

Note that max_execution_time counts CPU time of the script itself, not time spent waiting on the database or external calls on all platforms, but on a typical web request the practical effect is a hard ceiling on how long the page can take.

Solution

Raise the limit

In php.ini:

max_execution_time = 120

For a single CLI command without touching config:

php -d max_execution_time=300 artisan some:command

Reload PHP-FPM after editing php.ini:

systemctl reload php8.3-fpm

Remember nginx has its own timeout in front of PHP, if it's lower, nginx gives up first with a 504 Gateway Timeout. Both need to be raised together.

The real fix: don't do slow work in a request

CLI scripts (like artisan commands) default to no time limit, so the right home for slow work is a background queue, not the request cycle. In Laravel, dispatch it:

ProcessExport::dispatch($user);

The request returns instantly and the heavy lifting happens on a worker. Combine that with adding the missing database index and the timeout disappears for good. If the script is dying on memory rather than time, see PHP allowed memory size exhausted.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

Related articles

How to run PHP files

This fatal error means a PHP script ran longer than the allowed time limit and was killed. Raise the limit for legitimately long work, but the real fix is usually to make the script faster or move it to a queue.

Read more →

PHP Fatal error: Class "X" not found

This fatal error means a PHP script ran longer than the allowed time limit and was killed. Raise the limit for legitimately long work, but the real fix is usually to make the script faster or move it to a queue.

Read more →