How can we increase the execution time of a PHP script?

Last updated 2 years, 4 months ago | 329 views 75     5

PHP | max_execution_time directive in php.ini file

By changing the value of  max_execution_time in php.ini file

max_execution_time = 30; // in second
 

By default, the maximum execution time for PHP scripts is set to 30 seconds and if a script runs for longer than 30 seconds, PHP stops execution of the script and reports an error. Some of the script need more time to render/process the data such as you upload multiple file on the server at once, do lots of data manipulation on the client side or exporting and importing large amount of data using php script etc.

For handle such script you need to change the amount of time allowed by php to execute those script.

There are two ways to do so:

1. The first one is by changing the max_execution_time directive in your php.ini file. Just open your php.ini file and search for max_execution_time and change the execution time.

// search for 
max_execution_time = 30; // in second
	
//change like this
max_execution_time = 600; // in second

2. The second one is using ini_set() function. Just call it top of your script or inside your php function.

Example with script

<?php
	ini_set ( 'max_execution_time', 600);
	
	/*
		php scripts goes here...
	*/
?>

Example with function

<?php

function test()
{
	ini_set ( 'max_execution_time', 600);

	/*
		php scripts goes here...
	*/
}

?>