How to increase maximum execution time in PHP and WordPress?
A long job (an import, a big backup or a slow plugin) can stop with Maximum execution time exceeded. The limit is set by the PHP setting max_execution_time (in seconds). Ways to raise it:
- php.ini:
max_execution_time = 300 - .htaccess (Apache with mod_php):
php_value max_execution_time 300 - In code: call
set_time_limit( 300 );orini_set( 'max_execution_time', '300' );before the long job. - Your host panel: many hosts have a PHP settings page.
Here we check the value on a real page, before and after calling set_time_limit() from a small must use plugin:
<?php
add_action( 'wp_footer', function () {
echo '<!-- before: ' . ini_get( 'max_execution_time' ) . ' -->';
set_time_limit( 300 );
echo '<!-- after: ' . ini_get( 'max_execution_time' ) . ' -->';
} );
Terminal output
$ curl -s http://example.com/ | grep -o "<!– \(before\|after\): [0-9]* –>"
<!– before: 30 –>
<!– after: 300 –>
WP-CLI scripts have no time limit by default, which is why long jobs are often done with it. Some hosts block set_time_limit(), and a web server (Nginx or a proxy) can have its own timeout too. Do not set it too high on a live site.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| How to increase maximum execution time in PHP and WordPress? |