PHP Maximum execution time of N seconds exceeded - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

PHP Maximum execution time of N seconds exceeded
================================================

### [\#PHP](https://rocketeersapp.com/knowledge/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](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [About the error](#content-about-the-error)
2. [Why do I see this error](#content-why-do-i-see-this-error)
3. [Solution](#content-solution)
4. [Raise the limit](#content-raise-the-limit)
5. [The real fix: don't do slow work in a request](#content-the-real-fix-dont-do-slow-work-in-a-request)

[\#](#content-about-the-error "Permalink")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](/500-internal-server-error-laravel) or a half-rendered page.

[\#](#content-why-do-i-see-this-error "Permalink")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.

[\#](#content-solution "Permalink")Solution
-------------------------------------------

### [\#](#content-raise-the-limit "Permalink")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](/504-gateway-timeout-nginx). Both need to be raised together.

### [\#](#content-the-real-fix-dont-do-slow-work-in-a-request "Permalink")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](/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!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#PHP](https://rocketeersapp.com/knowledge/php)

- [How to run PHP files](https://rocketeersapp.com/knowledge/run-php-files)
- [PHP file upload exceeds upload\_max\_filesize](https://rocketeersapp.com/knowledge/php-file-upload-exceeds-upload-max-filesize)
- [PHP Warning: Undefined array key](https://rocketeersapp.com/knowledge/undefined-array-key-php)
- [PHP Fatal error: Allowed memory size exhausted](https://rocketeersapp.com/knowledge/php-allowed-memory-size-exhausted)
- [PHP: Call to a member function on null](https://rocketeersapp.com/knowledge/call-to-a-member-function-on-null)
- [PHP Fatal error: Class "X" not found](https://rocketeersapp.com/knowledge/php-class-not-found)

 [View all 11 articles →](https://rocketeersapp.com/knowledge/php)
