Fix PHP Error: Maximum Execution Time Exceeded
Your website shows the error message "Maximum execution time of 30 seconds exceeded" or your page keeps loading without a result. This is a PHP timeout error: your script takes longer than the allowed maximum execution time. In this guide, we explain what this means and how to fix it.
What is a PHP timeout error?
PHP has a built-in time limit for running scripts. By default this is 30 seconds (sometimes 60 or 120 seconds, depending on your hosting configuration). If a script takes longer, PHP stops execution and shows the following error message:
Fatal error: Maximum execution time of 30 seconds exceeded in /path/to/file.php on line 123
This time limit exists as a safeguard: it prevents stuck scripts from overloading your entire server. But for legitimate operations (large imports, database migrations, heavy calculations), the default limit can be too low.
Common causes:
- Large database queries: queries that process thousands of rows
- File uploads: uploading or processing large files
- Plugin or theme operations: updates, imports or exports that take a long time
- External API calls: connections to slow external services
- Infinite loops: programming errors that make a script hang
- Heavy image processing: scaling or converting large images
Fixing a PHP timeout as a website owner
Follow the steps below to increase the PHP timeout or fix the underlying problem.
1. Increase max_execution_time via php.ini
The most direct way to increase the timeout is via the php.ini configuration file:
max_execution_time = 300
This raises the limit to 300 seconds (5 minutes). On shared hosting, you can often create a .user.ini file in the root of your website with the same setting.
2. Increase the limit via wp-config.php
With WordPress, you can also set the time limit via wp-config.php:
set_time_limit(300);
Or add this PHP setting:
ini_set('max_execution_time', 300);
Place this line above the line /* That's all, stop editing!*/ in your wp-config.php.
3. Increase via the DirectAdmin PHP Selector
On DirectAdmin hosting, you can change the PHP settings via the control panel:
- Log in to DirectAdmin
- Go to Advanced Features → Select PHP Version (or PHP Selector)
- Click "Switch to PHP Options
- Find
max_execution_timeand set it to 300 - Click "Save
4. Increase via .htaccess
On Apache servers, you can also change the setting via .htaccess:
php_value max_execution_time 300
Note: This only works with mod_php, not with PHP-FPM or FastCGI. With PHP-FPM, you need to change the php.ini or the pool configuration.
5. Optimize the underlying problem
Increasing the time limit is a workaround. The real solution is often to optimize the script that takes too long:
- Optimize database queries: add indexes, limit the number of results with LIMIT, use pagination
- Batch processing: process large datasets in small batches instead of all at once
- Enable caching: store the results of heavy calculations in a cache (Redis, Memcached)
- Use background jobs: move heavy operations to a queue or cron job
- Speed up external calls: set timeouts for API calls and use async processing
6. Check for infinite loops
If the timeout keeps coming back, even after increasing the limit, there may be a programming error:
- Enable
WP_DEBUGto find the exact line - Check for while/for loops without a correct exit condition
- Check recursive function calls for a missing base case
- Deactivate recently installed plugins to find the culprit
Related PHP settings
Besides max_execution_time, there are more PHP settings that are time-related:
| Setting | Default | Function |
|---|---|---|
| max_execution_time | 30 | Maximum execution time per script (seconds) |
| max_input_time | 60 | Maximum time for parsing input (seconds) |
| memory_limit | 128M | Maximum memory usage per script |
| upload_max_filesize | 2M | Maximum upload file size |
| post_max_size | 8M | Maximum size of POST data |
With a VPS, you have full control over all these settings. On shared hosting, some settings are restricted by your hosting provider.
Frequently asked questions about PHP timeout errors
What does "Maximum execution time of 30 seconds exceeded" mean?
This error message means that a PHP script ran for longer than 30 seconds and was stopped by the server. The 30-second limit is the default value of the PHP setting max_execution_time. You can increase this limit via php.ini, wp-config.php or the control panel of your hosting package.
Is it safe to increase max_execution_time?
Yes, increasing it to 120 to 300 seconds is safe for most websites. However, don't set the limit to unlimited (0 = no limit), because this can let stuck scripts overload your entire server. A value of 300 seconds (5 minutes) is a good balance between functionality and protection.
Why do I get a PHP timeout during WordPress updates?
WordPress plugin and theme updates have to download, unpack and install files. With slow internet connections, large updates or overloaded servers, this can take longer than the timeout allows. Temporarily increase max_execution_time to 300 seconds and try the update again. Also consider upgrading to faster web hosting if this happens regularly.
Dealing with PHP timeouts caused by slow hosting? See our web hosting packages with LiteSpeed and NVMe SSD for the fastest PHP execution. Or choose a VPS with full control over all PHP settings.
0 van 0 vonden dit nuttig