Home  >  Article  >  Backend Development  >  How to use php set_time_limit method

How to use php set_time_limit method

藏色散人
藏色散人Original
2021-05-20 09:49:063238browse

php The set_time_limit method is used to set the maximum execution time of the script. Its usage syntax is "set_time_limit (int $seconds): bool". The parameter seconds represents the maximum execution time in seconds.

How to use php set_time_limit method

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

set_time_limit — Set the maximum execution time of the script

Description

set_time_limit ( int $seconds ) : bool

Set the time allowed for the script to run, in 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.

Parameters

seconds

Maximum execution time, in seconds. If set to 0 (zero), there is no time limit.

Return value

Returns true on success and false on failure.

Comments

Note:

The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. The maximum time for any script execution that occurs such as system calls using system(), stream operations, database operations, etc. is not included when the script is already running. In Windows, where measured times are real-valued, this is not the case.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to use php set_time_limit method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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