PHP program appears Fatal error:maximum execution time of seconds exceeded in hint

Source: Internet
Author: User
Tags ini safe mode time limit


Due to the many loops involved in recent programs and the complexity of processing, the execution timeout prompts when running the program are as follows: Fatal error:maximum execution time of seconds exceeded in D:\php\AppS Erv\www\sum3\test.php on line 3


Quite simply, it means that the execution time of the script exceeds the maximum of 30 seconds. This error is often encountered before, is generally directly in the page head plus a set_time_limit (0) processing, today deliberately this error processing method to do a summary.


1. Modify the PHP configuration file, find the php.ini file, it should generally be placed in your C:\WINDOWS directory, and then find max_execution_time = 30; set to the value you want, the unit is seconds, this line, This is the maximum execution time for a set of 30 seconds, and you can change the value to your expectations. (can also be set directly into: Max_execution_time = 0)

2. Using the Ini_set () function, not everyone can modify the php.ini file, then you can use this function to change your maximum execution time limit, such as: Ini_set (' max_execution_time ', ' 100 '); then set to 100 seconds, You can also set it to 0, so it is not limited to execution time.

3. Using the Set_time_limit () function, Set_time_limit (20) represents the maximum execution time plus 20 seconds, but Set_time_limit () will not result if the security mode is executed in PHP unless you use the first method.

Here are some of the explanations: set_time_limit---Limit the maximum execution time Set_time_limit (PH3, PHP4) set_time_limit---Limit the maximum execution time syntax: void set_time_limit (int s Econds) Note: Set the number of seconds a program allows to execute, and if the time limit is reached, the program will return an error.

Its preset limit time is 30 seconds, the value of max_execution_time is defined in the structure file (called Php3.ini in PHP3, PHP4 is called php.ini), and if the number of seconds is set to 0, there is no time limit.

When this function is called, set_time_limit () recalculates the maximum execution time from zero, that is, if the maximum execution time is a preset 30 seconds, and it takes 25 seconds to execute the program before calling the function Set_time_limit (20). The maximum execution time of the program will be 45 seconds.

Note: When PHP is executed in safe mode, Set_time_limit () will not have a result unless it is a time limit to turn off safe mode or modify the structure file (called Php3.ini in PHP3, called PHP.ini in PHP4).


Case: Set the program to run for 25 seconds if Safe mode is not turned on. For example:


<?php

if (!ini_get (' Safe_mode ')) {

Set_time_limit (25);

}

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.