.htaccess acts as a configuration file that permits configuration modifications on a per-directory basis.
Sometimes we need to increase the execution time limit of scripts to run our scripts smoothly.
In PHP, The standard script execution time limit is 30 seconds. So, when any PHP script takes execution time more than 30 seconds, the execution gets to stop, and a fatal error generated. .htaccess acts as a configuration file that permits configuration modifications on a per-directory basis.
Type of Error:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\test\test.php on line 4
We can handle this error by two methods. I am going to explain them one by one, let’s first check the value of execution limit.
To check this limit create a file get_info.php and place the below code.
<?php phpinfo(); ?>
It's a snip of the output. The actual output file is of multi-page, which will open in your browser.
Press ctrl+f and search max_execution_time
As you can see that the maximum execution time is 30 seconds. Let’s see how we can increase this time.
- By using htaccess file: create a .htaccess file in your root directory and place the following code.
php_value max_execution_time 300
- By using ini_set() PHP function: create a file set_time.php and add below code
<?php ini_set('max_execution_time', '300'); ?>
Include this file to the page on which you are facing a time-limit problem.
by using one of the above two methods, the execution time set to 3 minutes. You can increase it more according to requirement.
Let's verify our changes by cross-checking the value as described earlier. You can see that the max_execution_time is now 300 seconds.
Output After Changes:
Please leave your comments below . Kindly subscribe to our website for more such solutions.