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

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

When running PHP scripts that handle large amounts of data—such as exporting or importing a vast database or processing numerous files—you might encounter timeout errors. Typically, hosting providers set the maximum execution time to 30 or 60 seconds. If a script exceeds this limit, PHP will terminate it, resulting in error messages like “Maximum execution time of 30 seconds exceeded” or “Maximum execution time of 60 seconds exceeded.” For example, when using the Advanced Database Cleaner plugin, scanning for orphan tables or options can stall with large datasets. To prevent such interruptions and allow scripts to complete their tasks, you may need to increase your PHP max execution time. Here are three methods to extend the execution time for WordPress websites.

Method 1: Adjust the Max Execution Time in php.ini

If you can access your php.ini file, locate the max_execution_time parameter and increase its value to extend the time PHP scripts are allowed to run. For instance, you might set it to 300 seconds:

				
					max_execution_time = 300
				
			
This approach is generally the most effective way to increase your PHP max execution time. If you can’t access or modify your php.ini file, consider trying one of the alternative methods listed below.

Method 2: Adjust Max Execution Time in .htaccess

Locate the .htaccess file in your home directory. If it’s not visible, check your hidden files. Before making any changes, ensure you back up your .htaccess file. Then, add the following line to it:

				
					php_value max_execution_time 300
				
			

Method 3: Adjust the Max Execution Time in wp-config.php

Locate the wp-config.php file in your home directory. This file is the primary configuration file for your WordPress site. To increase the max execution time, add the following code to your wp-config.php:

				
					set_time_limit(300);
				
			

Do you need an expert? HIRE US NOW!