Three methods for PHP to set the maximum execution time of a script
The default maximum execution time in php.ini is 30 seconds, which is determined by max_execution_time in php.ini Variable Specify that if the script needs to run for a long time, such as sending a large number of emails, or analyzing a large amount of data, the server will forcibly terminate the executing program after 30 seconds. In this case, the maximum execution time of the PHP script must be changed.
Three ways to set the maximum execution time of a script in PHP
1. Set it in php.ini
max_execution_time = 120;
2. Through PHPini_setFunctionSet
ini_set("max_execution_time", "120");
3. Set set_time_limit(120);
function. If the above numbers are set to 0, there will be no limit. The script will continue to execute until the execution ends.
So, for scripts that need to be executed for a long time, generally just add the following code at the beginning of the php code
set_time_limit(0);
The above is the detailed content of What is the best setting for php script execution time?. For more information, please follow other related articles on the PHP Chinese website!