Home > Backend Development > PHP Problem > How to set program running time in php

How to set program running time in php

青灯夜游
Release: 2023-03-10 06:16:01
Original
3841 people have browsed it

Setting method: 1. Use the "ini_set("max_execution_time", "time value");" statement; 2. Use "set_time_limit (time value)". If the value is set to 0, it can be executed permanently until The program ends.

How to set program running time in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Method 1: Use ini_set() The value of the "max_execution_time" item in the function configuration

Syntax:

ini_set("max_execution_time", "时间数值");
Copy after login

PHP ini_set is used to set the value of php.ini, which takes effect when the function is executed. After the script ends, the setting becomes invalid. . You can modify the configuration without opening the php.ini file, which is very convenient for virtual spaces.

Method 2: Use the set_time_limit() function

set_time_limit - Set the maximum execution time of the script, syntax format:

set_time_limit (seconds)
Copy after login

Set the time allowed for the script to run , the unit is seconds. 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 default timeout is 30 seconds and set_time_limit(20) is called when the script has been running for 25 seconds, then the total time the script can run before timing out is 45 seconds.

If the parameter value seconds of this function is the maximum execution time, the unit is seconds. If it is set to zero (set_time_limit(0);), there is no time limit; that is, it will be executed permanently until the end of the program. If it is a number greater than zero, regardless of whether the program is completed, the set time limit will be reached. After a certain number of seconds, the program ends.

Return value: true on success, false on failure.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to set program running time in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template