Php page function setting timeout limit method, php page function timeout _ PHP Tutorial

Source: Internet
Author: User
The php page function sets the timeout limit. the php page function times out. Php page function setting timeout limit. php page function timeout this article describes how to set the timeout limit for php page functions. Share it with you for your reference. The specific method is as follows: php page function setting timeout limit method, php page function timeout

This article describes how to set the timeout limit for functions on the php page. Share it with you for your reference. The specific method is as follows:

When the page program execution times out, the system will prompt Fatal error: Maximum execution time of 300 seconds exceeded because the execution time of the program exceeds the Maximum allowed execution time. we have summarized several solutions for your selection.

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

The code is as follows:

Declare (ticks = 1 );
Function (){
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 to set the timeout Time of Your PHP program.
Solution:

1. modify the php. ini file with the following code:

The code is as follows:

Max_execution_time = 30; // Maximum execution time of each script, the original value of in seconds is 30 seconds. you can change the value to a greater value.

Remember to restart php after modification. this method takes effect for all programs.

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

The code is as follows:

Set_time_limit (300); // The maximum execution time. set this parameter to 300 seconds.

If the value is set to 0, the operation is not limited.

I hope this article will help you with PHP programming.

Examples in this article describes how to set the timeout limit for functions on the php page. Share it with you 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.