PHP - set_time_limit
Trieda
Metóda - set_time_limit
(PHP 4, PHP 5, PHP 7)
The set_time_limit() function sets how long the script can run.
It is related only to the current script - the function doesn't change the
global setting. The default value for the execution time of the script is 30
seconds if max_execution_time hasn't been changed in
php.ini.
The function sets the execution time from the monent it's been called. If the
script has run for example for 28 seconds, the max_execution_time
setting hasn't been changed and the function set_time_limit() has
been called with a parameter 15, the script can run for more 15
seconds. It's 43 seconds total.
The function doesn't work in safe mode.
If the operating system is not Windows, the time doesn't include system calls
made using the system() function, database queries or stream
operations etc.
Procedurálne
- function set_time_limit (int $seconds) : bool
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $seconds | int | The maximum number of seconds for the execution time of the script. If set to zero, no time limit is set. |
Mávratovej hodnoty
Vracia: bool
Returns true on success, false on failure.
The function can return null if the parameter isn't of the
integer type. It also emits a warning in this
situation.
Príklady
Test of return values:
<?php
var_dump(set_time_limit(30)); // True
var_dump(set_time_limit(0)); // True
var_dump(set_time_limit(15)); // True
var_dump(set_time_limit('Fail')); // Emits a warning and returns NULL
In real use:
<?php
set_time_limit(60);
// Parsing tons of data
// ...
if (!set_time_limit(60)) { // Again setting the execution time for the script - it resets the previous "timer"
// If it fails, it can save the data here
// ...
exit;
}
// Parsing next tons of data ...
// ...
