“Maximum execution time exceeded” PHP error
Why PHP stops long-running scripts, how to work within the limit with batching and cron, and when raising max_execution_time is appropriate.
On this page
Does this match what you’re seeing?
- Log shows ‘Maximum execution time of 30 seconds exceeded’
- Imports or backups stop partway
- A page loads for a long time and then errors
PHP Fatal error: Maximum execution time of 30 seconds exceeded in /home/user/domains/yourdomain.co.uk/public_html/import.php on line 88PHP stops scripts that run longer than max_execution_time, so a stuck script can’t tie up the server indefinitely.
Why long web requests are a bad idea anyway
Even with a higher limit, browsers, proxies and CDNs often give up on a request after a minute or two. Long jobs are better done in smaller pieces.
Better approaches
- Batching: process 500 records per request, then continue from where you stopped, either with a page that reloads itself or an AJAX loop.
- Cron: run heavy jobs on a schedule from the command-line PHP, where time limits usually differ. Running PHP scripts from cron: paths, output and common mistakes
- Import databases without PHP scripts where possible. Importing a database that’s too large for phpMyAdmin
- Fix slow queries — a missing database index can make a one-second job take minutes.
Raising the limit
If a job genuinely needs a bit longer, check whether max_execution_time is adjustable. Changing PHP settings: memory_limit, upload size and execution time In a script, you can request more time where allowed:
<?php set_time_limit(120);Server-level ceilings still apply.
Everything in this guide works on Traxio’s PHP hosting, which is £0.99 a month.
Common questions
How do I stop scripts timing out?
Raise max_execution_time in your PHP settings. Before you do, ask why the script needs so long — an import that takes minutes usually wants breaking into batches rather than a longer limit.
Spotted something out of date or unclear? Tell us and we’ll fix it.