Increase Maximum Eexecution Time Limit

PHP scripts are by default only allowed to be executed for a certain period of time, and when it reaches the time limit, it will stop and produce the following error;

Fatal error: Maximum execution time of 30 seconds exceeded in yourscript.php

This is to make sure a bad script don’t consume too much resource. To allow your PHP script to run at a longer time, you’ll need to increase the maximum execution time limit of PHP scripts using any of the following methods;

Method 1 – Modifying PHP global configuration file (php.ini)

Changing the setting in the global configuration file will affect all scripts that run on the system. The file is usually located in the following locations;

/etc/php5/apache2/php.iniUbuntu , Debian

Inside the file, search for the following line;

max_execution_time = 30

Change the value (in second) or set to 0 for infinite time and restart Apache for the setting to take effect.

Method 2 – Increase Maximum Eexecution Time Limit With htaccess

You can change the maximum execution time value using the following

php_value max_execution_time 2000

Method 3 – Within PHP script

his is probably the best method as the setting applies only to the particular script, and would not allow other poorly written scripts to also consume and waste the system’s resource.

To do this, call the following function in your PHP script with the maximum execution time in second as the parameter;

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

You can use 0 as parameter for infinite execution time.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *