Php page function setting timeout limit

Source: Internet
Author: User
When the page program execution times out, the system will prompt Fatalerror: Maximumexecutiontimeof300secondsexceeded because the program execution time exceeds the maximum allowed execution time... when the page program execution times out, the system will prompt Fatal error: Maximum execution time of 300 seconds exceeded because the program execution time exceeds the Maximum allowed execution time, I have summarized several options that suit you.

For functions, we can use the following method to directly set the timeout value for the function. 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"); (); 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:

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:

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

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


Address:

Reprinted at will, but please attach the article address :-)

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.