How to set timeout limit for php page function, php page function timeout
The example in this article describes how to set timeout limits for PHP page functions. Share it with everyone for your reference. The specific method is as follows:
When encountering a page program execution timeout, Fatal error: Maximum execution time of 300 seconds exceeded will be prompted because the program execution time exceeds the maximum allowed execution time. We have summarized several solutions for everyone to choose from.
For functions, we can use the following method to directly set the timeout period for the function. The code is as follows:
Copy code The code is 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 to just set the timeout for your PHP program.
Solution:
1. Modify the php.ini file, the code is as follows:
Copy code The code is as follows:
max_execution_time = 30; // Maximum execution time of each script, in seconds The original value is 30 seconds, you can change it Click.
Remember to restart php after making the change. This method will take effect on all programs after the change.
2. Modify your program and add code to the script that takes longer than the default value (30 seconds):
Copy code The code is as follows:
set_time_limit(300); // The maximum execution time is set here to 300 seconds
Set to 0 to indicate no time limit.
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/920620.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920620.htmlTechArticleHow to set timeout limit for php page function, php page function timeout This article describes how to set timeout limit for php page function method. Share it with everyone for your reference. The specific method is as follows...