PHP hints for more than 30 seconds for the longest execution time error resolution

Source: Internet
Author: User
Tags error handling
When you are doing a crawler, php is blank for a long time and then the following error message appears: Fatal error: Maximum execution time of 30 seconds exceeded in ...... very simple, meaning script Execution time exceeded the upper limit of 30 seconds. This error has been encountered before, usually in the head of the page plus a set_time_limit (0) processing, today specifically to summarize this error handling method. After consulting the relevant materials, there are basically three ways for the PHP introductory tutorial to deal with this error.

 
 
(1) modify the php configuration file php.ini file
Find the php.ini file and find it in this file: max_execution_time = 30 ; this line sets the number 30 to the value you want, in seconds. (Also can be directly modified to: max_execution_time = 0; / / no limit) Note that you need to restart the server after this modification.
 
(2) use the ini_set() function
For those who can't modify php.ini, you can use the ini_set() function to change your maximum execution time limit. Add the following code at the top of the program: ini_set('max_execution_time', '100'); The above setting is 100 seconds, you can also set to 0, then it is not limited to the execution time.
 
(3) use the set_time_limit () function
Add: set_time_limit(100) at the top of the program; it means that the maximum execution time is set to 100 seconds. Of course, you can also set the parameter to 0, meaning the same as above. The set_time_limit function specifies: void set_time_limit ( int $seconds ) The function of this function is to set the time in seconds that the script is allowed to run. If this setting is exceeded, the script returns a fatal error. The default value is 30 seconds, or the value defined in max_execution_time in php.ini if this value exists. When this function is called, set_time_limit() will restart the timeout counter from zero. In other words, if the timeout defaults to 30 seconds and set_time_limit(20) is called when the script has run for 25 seconds, then the script can run for a total of 45 seconds before timing out. This feature does not work when php is running in safe mode. There is no other way than turning off safe mode (set safe_mode to off in php.ini) or changing the time limit in php.ini. Case: If the security mode is not turned on, the setup program runs for 25 seconds. E.g:
 
12if(!ini_get('safe_mode')){
3 set_time_limit(25);
4}

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.