Open In App

Maximum execution time taken by a PHP Script

One important aspect of PHP programs is that the maximum time taken to execute a script is 30 seconds. The time limit varies depending on the hosting companies but the maximum execution time is between 30 to 60 seconds. The user may get errors of maximum time limit exceeds due to some heavy import or export of files or program which involves sending mail to many recipients. To avoid the situation, you need to increase the execution time limit.
This article describes how to change or control the maximum execution time of a PHP script.
Prerequisite required: 
You have already a custom php.ini file set up in your application or a request has to be done to the owner who maintains it. If some of the PHP scripts take longer time then the server stops and throws an error: 

Fatal error: Maximum execution time of..seconds exceeded in this_file.php on line...

To avoid this situation, you can change the max_execution_time directive in php.ini configuration file. Let us look at the ways by which we can set time for script execution in PHP. These are listed below: 

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 4000




// The program is executed for 3mns.
<?php
ini_set('max_execution_time', 180);
?>




<?php
// Sets to unlimited period of time
ini_set('max_execution_time', 0);
?>




<?php
ignore_user_abort();
?>

php_value name value
php_value max_execution_time 200

Article Tags :