Quantcast
Channel: BinaryTides » Coding
Viewing all articles
Browse latest Browse all 10

Php – Do not rely on set_time_limit too much

$
0
0
Php set_time_limit
Php has a function called set_time_limit which can be used to dynamically adjust the maximum execution time permitted to a script. It allows specifying the time in seconds and limits the script execution time to that many seconds.
The set_time_limit function whenever called, effectively extends the script execution time by that many seconds. So if the script has already run for 15 seconds and set_time_limit(30) is called, then it would run for a total of 30+15 = 45 seconds. That's how its designed to work.
The default time limit is generally 30 seconds and defined by the 'max_execution_time' option of php.ini
Use the ini_get function to get it.

ini_get('max_execution_time');

To find out the time already consumed by php use the getrusage function


$dat = getrusage();
echo $dat; // number of swaps
echo $dat; // number of page faults
echo $dat; // user time used (seconds)
echo $dat; // user time used (microseconds)


However the function itself can show varying behaviour across different platforms and environments and conditions. The documentation mentions
The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens...

Read full post here
Php – Do not rely on set_time_limit too much


Viewing all articles
Browse latest Browse all 10

Trending Articles