PHP Fatal error: Maximum execution time of 30 seconds exceeded means a script ran longer than PHP's max_execution_time. It usually appears during imports, backups, plugin updates or slow external API calls. Here is how to fix the maximum execution time exceeded error and when raising the limit is the wrong answer.
Before you start
- Note what you were doing when it failed and which file the error names (from
error_log). - Know your environment: cPanel hosting or a VPS with Nginx/Apache and PHP-FPM.
How the PHP time limit works
max_execution_timecounts the script's own CPU/run time (on Linux, time spent waiting on database queries and network calls is mostly not counted).max_input_timelimits time spent parsing uploaded data.- The CLI has no limit by default (0), which is why scripts that time out in a browser often work from SSH.
- The web server and PHP-FPM have their own timeouts, which can end the request first with a 504 error.
Raise the limit on cPanel hosting
- Open cPanel → Software → Select PHP Version → Options (or MultiPHP INI Editor).
- Set
max_execution_timeto e.g. 120 or 300 and save.
Raise the limit on a VPS
In the PHP-FPM php.ini (e.g. /etc/php/8.3/fpm/php.ini):
max_execution_time = 120Then raise the matching timeouts so they do not cut the request off first:
- PHP-FPM pool:
request_terminate_timeout = 130s(0 means disabled). - Nginx:
fastcgi_read_timeout 130s;in the PHP location block. - Apache with proxy_fcgi:
ProxyTimeout 130.
Restart PHP-FPM and reload the web server afterwards.
Per-script overrides
.user.ini:max_execution_time = 120- In code, for one long task:
set_time_limit(300); - WordPress: some plugins call
set_time_limit()themselves; hosting may still cap it.
Better fixes for long tasks
A web request that runs for minutes ties up a PHP worker and risks timeouts at the proxy, CDN or browser. Prefer:
- Command line: run imports, migrations and exports over SSH (
php script.php,wp import,php artisan), where there is no time limit. - Background jobs: queues (Laravel queues, WooCommerce Action Scheduler) process work in small chunks.
- Batching: import 500 rows per request instead of 50,000.
- Cron: schedule heavy maintenance tasks instead of triggering them from page loads.
- Faster code: slow queries and external API calls without timeouts are common culprits. Set a timeout on HTTP calls.
Check the fix
Confirm the active value with phpinfo() (search for max_execution_time) and rerun the task. If it now ends with a 504 instead, a web server or proxy timeout is lower than PHP's.
Troubleshooting
- Limit change has no effect: wrong php.ini, or the hosting enforces a maximum. Check Loaded Configuration File and Local Value in phpinfo.
- 504 Gateway Timeout instead of a PHP error: Nginx, Cloudflare (100-second limit on most plans) or a load balancer gave up first.
- Error at random places in the code: the script is just slow overall. Profile it or move it to the CLI.
Execution time FAQ
What value should max_execution_time be?
30–60 seconds for normal pages. Raise it temporarily for specific admin tasks rather than globally.
Is 0 (unlimited) safe?
Not for web requests: hung scripts would hold workers forever. It is the normal default for the CLI.
Why does the error mention a line in an unrelated file?
The timer simply ran out at that point; the time may have been spent elsewhere earlier in the request.
