Maximum execution time taken by a PHP Script Last Updated : 25 Jan, 2022 Comments Improve Suggest changes Like Article Like Report 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: Search for max_execution_time directive in the php.ini file and edit the value of it, as required by the PHP script. ; 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 = 4000The default value of the directive is changed as required. Note: We have to restart the web-server, once the changes are done in the configuration file. By this setting, the configuration is made global to all PHP scripts. Changes done to this file in an incorrect way can create problems to the web-server or live projects.Use PHP inbuilt function set_time_limit(seconds) where seconds is the argument passed which is the time limit in seconds. It is used, when the user changes the setting outside the php.ini file. The function is called within your own PHP code. Use set_time_limit(0) when the safe mode is off.Note: If the function is called at the very start of the program, then the value passed to the function will be the time limit for the execution of the script. Otherwise, if the function is called in the middle of the code, then the partial script is executed and then for the rest of the script, the time limit is applied.Use PHP inbuilt function ini_set(option, value) where the parameters are the given configuration option and the value to be set. php // The program is executed for 3mns. <?php ini_set('max_execution_time', 180); ?> It is used when you need to override the configuration value at run-time. This function is called from your own PHP code and will only affect the script which calls this function. Use init_set('max_execution_time'0) when you want to set unlimited execution time for the script.Note: Use init_set() function when the safe mode is off. php <?php // Sets to unlimited period of time ini_set('max_execution_time', 0); ?> Note: This function with '0' as a parameter is not a good programming practice but can be used for developing and testing purpose. Before the code is moved to live or production mode, make sure the settings are revoked.For allowing to run the script forever and ignore user aborts, set PHP inbuilt function ignore_user_abort(true). By default, it set to False which throws fatal error when client aborts to stop the script. php <?php ignore_user_abort(); ?> Use php_value command to change the settings in Apache configuration files and .htaccess files. Syntax: php_value name valueThis sets the value for that particular directive as specified. php_value max_execution_time 200Use of cPanel configuration setting options for changing the execution time of a script. This can be done in cPanel's dashboard and can be used for setting the time limit for PHP script. Comment More infoAdvertise with us Next Article Maximum execution time taken by a PHP Script G geetanjali16 Follow Improve Article Tags : Web Technologies PHP PHP Programs Similar Reads PHP Program for Maximum Equilibrium Sum in an Array Given an array arr[]. Find the maximum value of prefix sum which is also suffix sum for index i in arr[].Examples: Input : arr[] = {-1, 2, 3, 0, 3, 2, -1}Output : 4Prefix sum of arr[0..3] = Suffix sum of arr[3..6]Input : arr[] = {-2, 5, 3, 1, 2, 6, -4, 2}Output : 7Prefix sum of arr[0..3] = Suffix su 3 min read How to execute PHP Script in Website using XAMPP webserver ? First we have to install the XAMPP/WAMP webserver in our system. Please follow the link to download and install XAMPP/WAMP server. Link https://www.apachefriends.org/download.html After successful installation, the steps we should follow are- Open XAMPP control panel, if you want to link database to 2 min read Daylight Saving Time Handling in PHP Daylight Saving Time (DST) is the practice of turning the clock ahead as warmer weather approaches and back as it becomes colder again. The goal of Daylight Saving Time is to make better use of daylight by prolonging the amount of time we can spend outside during daylight hours. DST is a common prac 3 min read PHP Program to Find maximum element of each row in a matrix Given a matrix, the task is to find the maximum element of each row.Examples: Input : [1, 2, 3] [1, 4, 9] [76, 34, 21]Output :3976Input : [1, 2, 3, 21] [12, 1, 65, 9] [1, 56, 34, 2]Output :216556Approach : The approach is very simple. The idea is to run the loop for no_of_rows. Check each element in 2 min read How to measure the speed of code written in PHP? Use timestamp function to measure the speed of code. The timestamp function placed twice in a program one at starting of program and another at end of the program. Then the time difference between end time and start time is the actual speed of code. PHP uses microtime($get_as_float) function to meas 2 min read How to get the current Date and Time in PHP ? To get the current date and time in PHP, use the date() function, which formats UNIX timestamps into a human-readable format. It converts timestamps, measured in seconds since January 1, 1970, into a more understandable representation for users.Syntax: date('d-m-y h:i:s');Parameters: The date() has 2 min read PHP Program to Find the Size of Subarray With Maximum Sum Given an Array, the task is to find the size of the subarray that yields the maximum sum. This article provides a comprehensive guide on how to implement a PHP program to solve this problem efficiently.Examples: Input: Arr = [ 1, -2, 1, 1, -2, 1 ]Output: Length of the subarray is 2Explanation: The s 2 min read PHP Program for Maximum Difference Between Groups of Size Two Given an array of even number of elements, form groups of 2 using these array elements such that the difference between the group with highest sum and the one with lowest sum is maximum.Note: An element can be a part of one group only and it has to be a part of at least 1 group. Examples: Input : Ar 3 min read PHP Program For Rearranging An Array In Maximum Minimum Form - Set 2 (O(1) extra space) Given a sorted array of positive integers, this PHP program rearranges the array alternately: the first element is the maximum value, the second is the minimum value, the third is the second maximum, the fourth is the second minimum, and so on.Examples:Input: Arr = [ 1, 2, 3, 4, 5, 6, 7 ] Output: [ 3 min read How to get the last n characters of a PHP string? Write a PHP program to get last n characters of a given string. Examples: Input : $str = "GeeksforGeeks!" $n = 6 Output : Geeks! Input : $str = "GeeksforGeeks!" $n = 9 Output : forGeeks! Method 1: Tn this method, traverse the last N characters of the string and keep appending them in a new string. E 1 min read Like