How to Fix the “Maximum Execution Time Exceeded” PHP Error
The "Maximum execution time of X seconds exceeded" error means a PHP script ran longer than its time limit, so PHP halted it. The limit exists to stop a stuck script from tying up the server forever. Fixing it means either allowing a bit more time, or — better — making the slow operation faster.
The quick fix: increase the time limit
You can raise max_execution_time in your PHP settings in cPanel or in your php.ini file. The default is often 30 seconds; raising it to 120 or 300 gives long-but-legitimate tasks room to finish.
What usually triggers it
- A large database import or export through the browser.
- A backup or migration plugin processing a big site in one go.
- A slow external call to an API that takes too long to respond.
- An inefficient query or loop in custom code.
The better fix: remove the slowness
Rather than just allowing more time, tackle why it is slow. Optimise your database, break big jobs into batches, and cache expensive results so they are not recalculated every run.
For genuinely long tasks, avoid the browser
Web requests are meant to be quick. Long jobs — big imports, bulk processing — are better run as a cron job or over SSH, where the web time limit does not apply. This also avoids 504 gateway timeouts.
Frequently asked questions
What is a safe value for max_execution_time?
120 to 300 seconds handles most heavy tasks. Setting it extremely high is not ideal, because a truly stuck script would then run for far too long before being stopped.
My import keeps hitting the limit no matter what.
Very large imports are better done from the command line over SSH, which ignores the web timeout entirely. Alternatively, split the file into smaller parts.
The error only happens with one plugin.
That plugin is doing something slow. Check for a lighter alternative, run its heavy tasks off-peak, or increase the limit just enough for it to finish while you look for a better option.
Was this article helpful?