Home > Article > Backend Development > How to set program running time in php
Setting method: 1. Use the "ini_set("max_execution_time", "time value");" statement; 2. Use "set_time_limit (time value)". If the value is set to 0, it can be executed permanently until The program ends.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Method 1: Use ini_set() The value of the "max_execution_time" item in the function configuration
Syntax:
ini_set("max_execution_time", "时间数值");
PHP ini_set is used to set the value of php.ini, which takes effect when the function is executed. After the script ends, the setting becomes invalid. . You can modify the configuration without opening the php.ini file, which is very convenient for virtual spaces.
Method 2: Use the set_time_limit() function
set_time_limit - Set the maximum execution time of the script, syntax format:
set_time_limit (seconds)
Set the time allowed for the script to run , the unit is seconds. If this setting is exceeded, the script returns a fatal error. The default value is 30 seconds, or the value defined in max_execution_time in php.ini, if this value exists.
When this function is called, set_time_limit() will restart the timeout counter from zero. In other words, if the default timeout is 30 seconds and set_time_limit(20) is called when the script has been running for 25 seconds, then the total time the script can run before timing out is 45 seconds.
If the parameter value seconds of this function is the maximum execution time, the unit is seconds. If it is set to zero (set_time_limit(0);
), there is no time limit; that is, it will be executed permanently until the end of the program. If it is a number greater than zero, regardless of whether the program is completed, the set time limit will be reached. After a certain number of seconds, the program ends.
Return value: true on success, false on failure.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to set program running time in php. For more information, please follow other related articles on the PHP Chinese website!