PHP script execution timeout solution _ PHP Tutorial

Source: Internet
Author: User
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'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.