How to increase your PHP Max Execution Time in case of a timeout error

When executing PHP scripts that manipulate large amounts of data, such as exporting/importing a large database, processing a big number of files, etc. timeout errors may occur. Most hosting companies set the max execution time to 30 or 60 seconds.

PHP will end scripts and you will get error messages such as “Maximum execution time of 30 seconds exceeded” or “Maximum execution time of 60 seconds exceeded”. For the case of the Advanced Database Cleaner plugin, you will notice that the scan for orphan tables/options may get stuck when scanning a large amount of data.

To allow such scripts to finish the process, you may need to increase your PHP max execution time. Bellow three possible methods to increase your execution time for WordPress websites.

Please keep in mind that these methods are standard instructions, as we cannot cover all web hosting environments variations. If you cannot increase your max execution time following these methods, or if you do not have enough technical skills to do so, the best solution is then to contact your web hosting company and tell them to increase it for you.

Note: If one of the following ways works for you, no need to apply them all

Method 1: Edit the max execution time in php.ini

If you have access to your php.ini file, search for the max_execution_time parameter and increase it to allow your PHP scripts to run correctly. Put 300 seconds for example.

max_execution_time = 300

This method is the best solution to increase your PHP max execution time. However, if for any reason you do not have access to your php.ini file or you can edit it, try one of the next methods.

Method 2: Edit the max execution time in .htaccess

This file can be found in your home directory. If you cannot see it there, verify if it is not among your hidden files. Make sure you back up your .htaccess file before you edit it. Then add the following line to your .htaccess:

php_value max_execution_time 300

Method 3: Edit the max execution time in wp-config.php

This file can be found in your home directory. It is the main configuration file of your WordPress website. Add the following to your wp-config.php:

set_time_limit(300);