Maximum execution time PHP Origin: Application & API Last updated 14 Oct 2026

PHP Fatal error: Maximum execution time of 30 seconds exceeded

The script ran longer than max_execution_time and PHP stopped it.

Exact message you may see Maximum execution time of 30 seconds exceededMaximum execution time
Seen on: PHP

Meaning

PHP limits CPU time per request (default 30s; unlimited on CLI). Long imports, slow external calls or infinite loops hit it.

Common causes

  • Slow database queries
  • Synchronous calls to slow external APIs
  • Large imports/exports in a web request
  • Infinite loops

⚡ Quick fix

  1. Move long tasks to CLI/cron or a queue
  2. Optimize the slow query/API call
  3. set_time_limit(120) for known-long scripts
  4. Check the FPM/proxy timeouts too, or you’ll get a 504 instead

Detailed fix by platform

PHP

  1. php.ini: max_execution_time = 120. For FPM also request_terminate_timeout in the pool config.

Code examples

Run long work from the CLI (no time limit) via cron

bash
# crontab -e  → every 5 minutes, process the import queue
*/5 * * * * /usr/bin/php /var/www/app/bin/process-imports.php >> /var/log/imports.log 2>&1

Raise the limit only around a known-long block

php
set_time_limit(300);          // resets the timer to 300s from now
generateYearlyReport();
set_time_limit(30);           // back to normal

Also raise the PHP-FPM request_terminate_timeout and proxy timeouts, or you will get a 504 instead.

How to diagnose

  1. Location — Which file/line was executing when the limit hit (it is in the message)?
  2. Bottleneck — Time the DB queries and external HTTP calls in that request
  3. Limits — Compare max_execution_time, FPM request_terminate_timeout and proxy timeouts
  4. Placement — Should this work run in a queue/cron instead of a web request?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

504 — HTTP 504 Gateway Timeout (HTTP)504524 — Cloudflare Error 524: A Timeout Occurred (Cloudflare)524Allowed memory size exhausted — PHP Fatal error: Allowed memory size of X bytes exhausted (PHP)Allowed memory size e…ArgumentCountError — Fatal error: Uncaught ArgumentCountError: Too few arguments to function foo(), 1 passed and exactly 2 expected (PHP)ArgumentCountErrorCall to member function on null — Fatal error: Uncaught Error: Call to a member function x() on null (PHP)Call to member functi…Call to undefined function (WordPress) — WordPress: Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() / add_action() / get_header() (WordPress)Call to undefined fun…Cannot redeclare — Fatal error: Cannot redeclare function foo() (previously declared in …) (PHP)Cannot redeclarecURL error 28 — cURL error 28: Operation timed out after 30001 milliseconds with 0 bytes received (PHP)cURL error 28Maximum e…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.