PHP page function set time-out limit method, PHP page function Timeout _php tutorial

Source: Internet
Author: User

PHP page function to set the time-out limit method, PHP page function timeout


This article describes the method of setting the timeout limit for PHP page functions. Share to everyone for your reference. Here's how:

Encounter the page program execution timeout will remind fatal Error:maximum execution time of the seconds exceeded is because the program executes more than the maximum allowable execution time, the solution we summed up a few for everyone to choose.

For functions we can use the following method, directly to the function set timeout time to operate, the code is as follows:
Copy the Code code as follows: Declare (ticks = 1);
function A () {
Sleep (10);
echo "a Finishi";
}
Function B () {
echo "Stop";
}
Function C () {
Usleep (100000);
}

function sig () {
throw new Exception;
}

try{
Pcntl_alarm (1);
Pcntl_signal (SIGALRM, "sig");
A ();
Pcntl_alarm (0);
}catch (Exception $e) {
echo "Timeout";
}
b ();
A ();
b ();
For file or program code, you can use set_time_limit just to set the time-out for your PHP program.
Workaround:

1. Modify the php.ini file with the following code:
Copy the Code code as follows: Max_execution_time = 30; Maximum execution time of each script, in seconds original value 30 seconds, you can change the larger point.

After the change, remember to restart PHP, the method changed after the effective for all programs.

2. Modify your program to include the code in a script that takes more time than the default (30 seconds):
Copy the Code code as follows: Set_time_limit (300); Maximum execution time set here for 300 seconds

Set to 0 to indicate no time limit.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/920620.html www.bkjia.com true http://www.bkjia.com/PHPjc/920620.html techarticle PHP page function to set the time-out limit method, PHP page function Timeout This article describes the PHP page function setting time-out limit method. Share to everyone for your reference. The specific method is as follows ...

  • 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.