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

Last updated 5 years, 7 months ago | 1256 views 75     5

Tags:- PHP

PHP | max_execution_time directive in php.ini file

By changing the value of  max_execution_time in the 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 the execution of the script and reports an error. Some of the scripts need more time to render/process the data such as you upload multiple files on the server at once, do lots of data manipulation on the client-side or exporting and importing a large amount of data using PHP script, etc.

To handle such a script you need to change the amount of time allowed by PHP to execute those scripts.

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 the 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...
	*/
}

?>