"Maximum execution time exceeded" in PHP — What It Means and How to Fix It
What the PHP error "Maximum execution time exceeded" means and how to fix it.
Published October 31, 2026
A script ran longer than max_execution_time allows, so PHP stopped it. Slow queries, big imports and infinite loops are typical causes.
What it means and why it happens
The limit protects the server. For long jobs, move work to a queue or CLI script rather than raising limits for web requests.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
Fatal error: Maximum execution time of 30 seconds exceeded
Practical examples
Code that triggers it
<?php
while (true) { /* never ends */ }The fix
<?php
set_time_limit(300); // only when really needed
// better: dispatch a background job
dispatch(new ImportJob($file));CLI has no limit by default
php artisan import:run # max_execution_time is 0 in CLICommon mistakes
- Raising the limit instead of optimising the query.
- Long jobs in web requests.
- Infinite loops without exit conditions.
Key takeaways
- Maximum execution time exceeded: A script ran longer than max_execution_time allows, so PHP stopped it.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Where is it set?
max_execution_time in php.ini or set_time_limit() at runtime.
How do I find which line caused Maximum execution time exceeded?
The error message and stack trace show the file and line; start there and work backwards.