Troubleshooting

Maximum execution time of X seconds exceeded in x.php

Reviewed on 2 min read PHP errors PHP

Long operations, such as exporting or importing data, regenerating thumbnails or restoring a backup with a plugin, can end with this error:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/usuario/public_html/x.php on line 123

It means the script has exceeded the maximum time PHP allows it to run (max_execution_time). The solution is to increase that time.

Option 1: in .htaccess

This only affects the website where you add it. Open the .htaccess in public_html or in the application's folder from cPanel's File Manager (if it does not exist, create an empty file with that name) and add at the top:

php_value max_execution_time 300

300 is the number of seconds (5 minutes). Save and repeat the operation.

Option 2: in Select PHP Version

  1. In cPanel, go to Select PHP Version and open the Options tab.
  2. Change max_execution_time to 300.

The change is saved immediately and affects all the websites in the account that use that PHP version.

If it still appears

  • Raise the value gradually (600, 900). If an operation needs more than 15 minutes, it is not a good idea to keep raising it: split it into smaller parts (export by date ranges, import in several files) or run it via SSH, where there is no PHP time limit.
  • If the error appears on a normal page of the website, not in a long task, the problem is not the limit but something that hangs: a slow query, a call to an external service that does not respond or a plugin loop. PHP X-Ray tells you where that request's time goes.

When you finish the long operation, you can go back to the previous value so that a stuck script does not use resources for minutes.

You may also find useful

Something wrong or out of date? Tell us and we will review it.