31 December 2010

How to increase php script execution time

Sometimes we need to execute large php scripts but it gives following error:
PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /usr/local/apache/vhosts/abcd.com/htdocs/sites/all/modules/example.php on line 230

In such situations we can avoid this error by using one of the following methods:

Method 1

Place this code at the start of your php script.
ini_set('max_execution_time', 180); 

In the above code “180” is number of seconds.

180 seconds = 3 Minutes

Therefore the above code will increase the page execution time to 3 minutes.

Method 2

We can also use the following piece of code. But it won’t work in the safe mode.
set_time_limit(180);

180 is again the number of seconds. So the above code will also increase the page execution time to 3 minutes. If this value is set to zero then there will be no limit on the execution time.

No comments: