PHP page function Setting timeout limit method _php tips

Source: Internet
Author: User

The example in this article describes the method for setting time-out limits for PHP page functions. Share to everyone for your reference. The specific methods are as follows:

When you run into a page program to perform a timeout, you will be reminded that fatal error:maximum execution time of seconds exceeded is because the program is executing more than the maximum allowable execution time, and we have summed up a few for you to choose from.

For functions, we can use the following method to set the timeout time directly to the function, the code is as follows:

Copy 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 files or program code you can use Set_time_limit just to set the timeout for your PHP program.
Workaround:

1. Modify the php.ini file, the code is as follows:

Copy Code code as follows:
Max_execution_time = 30; Maximum execution time of the per script, in seconds original value 30 seconds, you can change the larger point.

After the change, remember to restart PHP, the method changed to All programs.

2. Modify your program and add code to your script that takes longer than the default value (30 seconds):

Copy Code code as follows:
Set_time_limit (300); Maximum execution time set 300 seconds here

Set to 0 means no limit.

I hope this article will help you with your PHP program design.

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.