Home > Article > Backend Development > Solution to PHP script execution timeout_PHP tutorial
The default script execution timeout in PHP is 30 seconds. If you do not set it, it will time out after 30 seconds if your script has not been executed. Let me explain in detail how to solve the PHP script execution timeout. .
The default maximum execution time in php.ini is 30 seconds. Although the value of max_execution_time in php.ini can be adjusted to achieve the goal, in some cases there is no condition to modify php.ini. How to solve this problem? .
One way is to add
in your PHP scriptThe code is as follows | Copy code | ||||
|
Another method is to execute the script from the command line. When executing the script from the command line, the maximum running time is set to unlimited.
Modify the script execution time limit of php.ini
Edit php.ini and modify the max_execution_time value:
代码如下 | 复制代码 |
max_execution_time=500 |
The code is as follows | Copy code |
max_execution_time=500 |
//This modification requires reloading php.ini and restarting the web server to take effect.
代码如下 | 复制代码 |
php_value max_execution_time 500 |
The code is as follows | Copy code | ||||
php_value max_execution_time 500
|
Set the maximum execution time in the script
The code is as follows | Copy code | ||||
|
The code is as follows | Copy code |
set_time_limit(0); |
set_time_limit is used to set the timeout of the script. This function stipulates that the program must run to completion within the specified number of seconds from the time the sentence is run. If the timeout expires, the program will exit with an error.
The following is an example. There are 10,000 pieces of data. To modify some of the data, use PHP to perform the processing step by step. The code is as follows:
action.php
The code is as follows
|
Copy code
|
||||
$stid = isset($_GET['stid'])?$_GET['stid']:0; | function dosomething(){
true