How to Increase PHP Max Execution Time in WordPress?
PHP is server side scripting language which is the backbone of WordPress websites. WordPress core, themes and plugins contain PHP files that help you to get content from the database and assemble the page layout. However, the entire process of running any PHP script is to be completed within a limited time (generally in seconds). In order to control the script running time, PHP has a variable called max_execution_time. It is essential to setup this parameter to desired value to protect your server and allocate the server resources to real users visiting the site instead of running a poorly written script in the background.
WordPress SEO: Optimize WordPress site with free WordPress SEO guide.
Why Execution Time is Limited?
On most hosting servers, the default execution time is set as 30 seconds. However, some shared hosting companies may restrict to lower values. There are good reasons for restricting the maximum PHP execution time on WordPress.
- Many hackers inject PHP files to run a script on your site. Restricting the script running time will help you to harden the security of your site.
- Some legitimate scripts like broken link checker plugins will run the script to scan all pages on your site. This may work well for the sites with 100 pages. However, running a script on a site with 10K posts will bring the server down.
- Old and poorly written PHP scripts can run long time and cause fatal errors.
Restricting maximum PHP execution time in server can help to stop these scripts running too long and affects real users on the site.
Why You May Need to Increase?
Though there are good reasons to limit PHP execution time on WordPress sites, there are also reasons why you should increase the limit.
- Sometime updating WordPress core, theme or plugins need large amount of data to be downloaded. You can setup the maximum file upload size with post_max_size parameter. However, the PHP script should also run for long time in order for the upload to complete on your server. Otherwise, you will get update failed error due to timeout.
- Many commercial WordPress themes offer custom demo import with large content. You may need to increase max_input_vars and max_execution_time parameter values in order to complete demo importing process. In addition, you may also need to increase maximum PHP memory size for the heavy plugins and themes to work properly.
How to View Max Execution Time?
Some hosting companies like Bluehost and SiteGround offers PHP Manager app in your account. You can use this app to find the max_execution_time setup for your site. For example, follow the below instructions in SiteGround hosting.
- Login to your hosting account and go to “Websites” section.
- Click on “Site Tools” link against the site you want to check the value.
- Find PHP Manager app under “Devs” section or use the search option to find the app.
- Go to “PHP Variables” section and scroll dow.
- Locate max_execution_time variable to find the default value assigned to it.
- SiteGround hosting allows 120 seconds as a default value which should be sufficient in most cases.
- In addition, you can’t modify this value from this app.
On Bluehost hosting, you can use MultiPHP INI Editor app to find the max execution time value. If you are not able to find the default value, the best option is to ask your host to check for you.
How to Increase PHP max_execution_time in WordPress?
If you are receiving error like timeout, you can increase PHP max_execution_time to resolve the issue. You can do that using one of the following methods:
- Editing wp-config.php File
- Adding htaccess Directive
- Using php.ini File
- Using custom apps from server (for Bluehost)
For first three options, you have to edit configuration files using File Manager app from your hosting account. Alternatively, you can use FTP to access your site remotely and modify the file’s content.
Important: It is a good idea to backup the original files before you editing.
1. Increase PHP Execution Time with wp-config.php
Go to your WordPress root installation and find wp-config.php file. Below is an example screenshot of locating the file from File Manager app.
Instead of File Manager, you can also use FTP account to modify wp-config.php file.
Add the below line before it says /* That’s all, stop editing! Happy blogging. */. 100 in this example indicates the maximum execution time of 100 seconds, you can change to any desired value for your need.
/** Change PHP Max Execution Time */ set_time_limit(100);
It should look like below:
2. Increase PHP Execution Time with htaccess
Instead of editing wp-config file, you can add the below directive in htaccess file on your server root.
php_value max_execution_time 100
Note: .htaccess file is hidden by default. You have to enable viewing hidden files in FTP client to view this file. In most cases, File Manager will show all files without hiding.
3. Increase PHP Execution Time with php.ini
The last and preferred option is to use php.ini file.
- Go to your server’s root and check whether you have php.ini file available. If the file is available, edit and add the below code.
max_execution_time = 100
- If the file is not available, you can create a php.ini file using plain text editors like Notepad++ or Brackets. Add the above code in the file and upload on your server’s root.
4. Using Custom Server Apps
This option is available only on certain hosting companies like Bluehost. We explain here with Bluehost, you have to confirm the availability of this type of apps with your hosting company.
- Login to your Bluehost account and click on the “Advanced” section.
- This will take you to cPanel.
- Search and open MultiPHP INI Editor app.
- Choose the domain you want to change the limit.
- Scroll down to find max_execution_time PHP directive and change the value.
- Click “Apply” button at the bottom to save your changes.
- Bluehost sets the default value for max execution time as 30 seconds and limits the maximum value of 90 seconds.
Risks in Increasing Execution Time
Setting the value too high like 1000 seconds may potentially damage your server if there is a script running for such a long time. In addition, hackers or malicious scripts can run long time without termination affecting your site’s performance on the frontend. In order to protect the server, many hosts do not allow you to modify max_execution_time value more than the allowed limit.
Even you define the values using one of the above methods, it may not work if your host does not allow. The best option is to consult with your host and ask for help if you are struck with errors like update failed due to timeout.