Home > Article > Backend Development > How to set the maximum connection time in php
The method to set the maximum connection time in php: 1. Set max_execution_time in php.ini; 2. Set it through the ini_set function of PHP; 3. Set it through the set_time_limit function.
The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
How to set the maximum php connection time?
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 the max_execution_time variable in php.ini 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. Set it through PHP's ini_set function
ini_set("max_execution_time", "120");
3. Set through the set_time_limit function
set_time_limit(120);
If the above numbers are set to 0, there will be no limit, and the script will continue to execute until the end of execution.
Therefore, for scripts that need to be executed for a long time, generally add the following code at the beginning of the PHP code
set_time_limit(0);
Recommendation: "PHP Video Tutorial"
The above is the detailed content of How to set the maximum connection time in php. For more information, please follow other related articles on the PHP Chinese website!