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.