Php Maximum execution time of 30 seconds exceeded webpage timeout solution

Source: Internet
Author: User
Tags ini time limit

Let's take a look at the example.

Example

The code is as follows: Copy code

Function geturl ($ url, $ userinfo, $ header)
{
$ Ch = curl_init ();
$ Timeout = 1;
Curl_setopt ($ ch, CURLOPT_URL, "$ url ");
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header );
Curl_setopt ($ ch, CURLOPT_REFERER, "http://www.111cn.net /");
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_USERAGENT, "$ userinfo ");
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout );
$ Contents = curl_exec ($ ch );
Curl_close ($ ch );
Return $ contents;
 
}

Execute for a while to discover

Fatal error: Maximum execution time of 30 seconds exceeded in D: phpAppServwww360dtest. php on line 3

Add

The code is as follows: Copy code

Set_time_limit (0); // Set the timeout value.

In this way, there is no problem. Next I will briefly introduce the set_time_limit details.

Set_time_limit-maximum execution Time: set_time_limit (PH3, PHP4) set_time_limit-maximum execution time syntax: void set_time_limit (int seconds) description: sets the number of seconds a program can run, if the time limit is reached, the program will return an error.

The default limit time is 30 seconds. The value of max_execution_time is defined in the structure File (php3.ini in PHP3, php in PHP4 and PHP5. ini). If the number of seconds is set to 0, there is no time limit.

When you call this function, set_time_limit () calculates the maximum execution time from scratch. That is, if the maximum execution time is 30 seconds, however, if it takes 25 seconds to execute the program before calling set_time_limit (20), the maximum program execution time will be 45 seconds.

Some friends said they could modify apache % C5 % E4 % D6 % C3/"target =" _ blank "> apache configuration, but I didn't test it.

1. Modify APACHE settings and find a parameter in PHP. INI:

Max_execution_time

Increase the subsequent values and restart the APACHE service (centos: service httpd restart.

For example

Max_execution_time= 600

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.