PHP script execution timeout solution. In php, the default time-out period for script execution is 30 seconds. if you do not set the time-out period to 30 seconds, if your script has not been executed, it will time out, next I will explain how to solve this problem. by default, PHP script execution timeout is 30 seconds, if you haven't set it 30 seconds later, if your script has not been executed, it will time out. next I will explain how to solve the PHP script execution timeout problem.
Php. the default execution time in ini is 30 seconds, although php can be adjusted. max_execution_time value in ini to achieve the goal, but in some cases, php is not allowed to be modified. ini, how to solve this problem.
One way is to add
| The code is as follows: |
|
|
Ini_set ('max _ execution_time ', '0 '); |
Set the running time to 0 (unlimited value );
Another method is to execute the script under the command line. when the script is executed using the command line, the maximum running time is set to an infinite value.
Modify the execution time limit of php. ini scripts
Edit php. ini and modify the max_execution_time value:
| The code is as follows: |
|
|
Max_execution_time= 500 |
// You need to reload php. ini and restart the web server to make the modification take effect.
Set the script execution time through the. htaccess file
| The code is as follows: |
|
|
Php_value max_execution_time 500 |
Set the maximum execution time in the script
| The code is as follows: |
|
|
Ini_set ('max _ execution_time ', 500 ); |
Cancel the script time limit using php functions
| The code is as follows: |
|
|
Set_time_limit (0 ); |
Set_time_limit is used to set the script time-out time. this function specifies that the program must end in the specified number of seconds from the time of running the sentence. if the time-out occurs, the program exits with an error.
The following is an example. There are 10000 pieces of data. to modify some of the data, use PHP to perform step-by-step processing. the code is as follows:
Action. php
| The code is as follows: |
|
|
$ Stid = isset ($ _ GET ['stid'])? $ _ GET ['stid']: 0;
$ Endid = $ stid + 100;
$ Maxid = 10000;
Function dosomething (){
// Operations that take a long time
......
}
$ SQL _string = "select * from 'table' where id> '$ stid' and id <=' $ endid' order by id ";
$ Datas = getdata_bysql ($ SQL _string );
Foreach ($ datas as $ data ){
// Process data
.....
Echo $ id. "processing completed.
";
If ($ id >=$ maxid) {exit ;}
}
If ($ stid <= $ maxid ){
$ Stid =$ stid + 100;
$ Url = "action. php? Stid = $ stid ";
Echo $ url;
Echo' |