How to Increase Max Execution Time (300s) for Your Website
The Max Execution Time setting in PHP determines the maximum time a script is allowed to run before being terminated. If your website handles long-running tasks, such as large file uploads, data imports, or plugin/theme updates, you might encounter errors like "Maximum execution time exceeded." Increasing the Max Execution Time can resolve these issues.
What Is Max Execution Time?
The max_execution_time
directive in PHP defines the time limit (in seconds) for script execution. By default, this is set to 30 seconds, but many hosting environments set it to 300 seconds. If a script runs longer than this time, it will terminate to prevent server overload.
Step 1: Check the Current Max Execution Time
Before making changes, determine the current max_execution_time
value:
A) Using PHP Info
- Create a file named
phpinfo.php
with the following code:<?php phpinfo(); ?>
- Upload the file to your website's root directory.
- Open the file in your browser (e.g.,
http://yourwebsite.com/phpinfo.php
). - Look for
max_execution_time
in the output.
B) Using Your Website Admin Panel
- Log in to your website's admin panel.
- Navigate to System Info or Server Settings.
- Look for the
max_execution_time
value.
Step 2: Increase Max Execution Time
Here are several methods to increase the max_execution_time
value, depending on your hosting environment:
A) Edit php.ini
- Access your server via FTP or your hosting control panel.
- Locate the
php.ini
file (commonly in the root directory or/etc/
). - Open the file and add or update the following line:
max_execution_time = 300
Replace300
with the desired value, such as600
for 10 minutes. - Save the file and restart your server.
B) Modify .htaccess
(For Apache Servers)
- Open the
.htaccess
file located in your website’s root directory. - Add the following line:
php_value max_execution_time 300
Replace300
with your desired value. - Save the file. The changes will take effect immediately.
C) Update Using cPanel or Hosting Dashboard
- Log in to your hosting provider’s control panel.
- Navigate to PHP Settings or MultiPHP INI Editor.
- Find the
max_execution_time
option. - Increase the value to
300
or higher (e.g.,600
). - Save the changes.
D) Use a .user.ini
File (For Shared Hosting)
- If you’re on shared hosting, create or edit a
.user.ini
file in your website’s root directory. - Add the following line:
max_execution_time = 300
- Save the file. Changes may take a few minutes to apply.
E) Set Using WordPress wp-config.php (Temporary Solution)
- Open the
wp-config.php
file in your WordPress installation directory. - Add the following line before
/* That's all, stop editing! Happy publishing. */
:@ini_set('max_execution_time', 300);
This method overrides the server setting but is temporary and may not work on some hosts.
F) Contact Your Hosting Provider
If you’re unable to modify the settings yourself, contact your hosting provider and request an increase in max_execution_time
.
Step 3: Verify the New Max Execution Time
- Refresh your website or clear the server cache.
- Revisit the
phpinfo.php
file or your admin panel to confirm the updated value. - Test the functionality that was previously timing out.
Troubleshooting Common Issues
- Changes Not Applied: Ensure you edited the correct configuration file and restarted the server if required.
- Shared Hosting Restrictions: Some hosting providers enforce strict limits. Contact them for assistance.
- Syntax Errors: Ensure there are no typos in the
.htaccess
orphp.ini
files.
Best Practices
- Avoid setting excessively high values to prevent server strain.
- Monitor your server performance and logs to ensure stability after increasing the limit.
- Use optimized scripts and processes to reduce execution time wherever possible.
Conclusion
Increasing the Max Execution Time is essential for handling long-running scripts on your website. By following the steps outlined above, you can prevent timeout errors and ensure smooth operations. If you encounter difficulties, your hosting provider can assist in adjusting the settings for you.