top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

set_time_limit() - is it CPU time or elapsed time in PHP?

+1 vote
349 views

This function limits the"execution time" for a script. Is this CPU time or elapsed (wall-clock) time?

I'm asking because I'm running Win7 in a VirtualBox VM under OS X Mavericks. I've got an app that runs a number of scripts, using PHP 5.5.9. All runs correctly, but quite slowly, and a one script reports taking 20 secs or so of elapsed time when I might have expected 2 or 3 at most (as the same script running under OS X does).

I know that there is a note in the online doc for this function that says that under windows, extra time such as database calls is included. Would that include SQLite calls which wouldn't be included for the OS X version?

I've got a windows user whose scripts are actually running out of time, so I may have to add a php_value to the apache config to crank up the time limit.

posted Apr 12, 2014 by Gurminder

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote

This function limits the"execution time" for a script. Is this CPU time or elapsed (wall-clock) time?

It’s elapsed time and technically it doesn’t so much limit the execution time so much as set it from the moment you call the function.

I'm asking because I'm running Win7 in a VirtualBox VM under OS X Mavericks. I've got an app that runs a number of scripts, using PHP 5.5.9. All runs correctly, but quite slowly, and a one script reports taking 20 secs or so of elapsed time when I might have expected 2 or 3 at most (as the same script running under OS X does).

There could be any number of reasons why there is such a big difference between the different platforms. Virtual boxes tend to be significantly slower than their host machines, especially when it comes to IO operations.

I know that there is a note in the online doc for this function that says that under windows, extra time such as database calls is included. Would that include SQLite calls which wouldn't be included for the OS X version?

Under Windows it’s elapsed time spent executing the PHP script regardless of what it’s doing, but under other platforms it’s elapsed time spent executing PHP code only (so not including time spent executing other processes, running database queries, etc). So yes, time spent executing sqlite queries would only be included on Windows. If your queries are causing the order of magnitude difference in execution time your problem has nothing to do with PHP!

I've got a windows user whose scripts are actually running out of time, so I may have to add a php_value to the apache config to crank up the time limit.

Rather than doing that I would advise the user to modify their script to keep calling set_time_limit at regular intervals to extend the time allowed. Doing that will ensure that if the script actually gets stuck in a loop or gets blocked by something external the script will be killed and the effect will be minimal. When I’m doing something like processing large data files I’ll call set_time_limit on every iteration of the loop with a reasonable maximum time for each chunk of the file.

answer Apr 13, 2014 by Anderson
Similar Questions
+2 votes

I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....

anyway I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:

exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04". So - where is the hour value of '07' coming from?? And how do I get this right?

+1 vote

I am able to see the absolute (exact) time on Win-XP of a file when it was last modified in hours, minutes, and seconds ("Today, May 11, 2014, 6:06:09 AM") by displaying the file properties.

On Windows 7, it displays the time as relative and a rough estimate ("Today, May 11, 2014, 2 hours ago"). How do I change it so it displays absolute time like Windows XP.

+5 votes

I am running Python 2.7 and would like to be able to calculate to the second the time difference between now and some future date/time in the same timezone while taking into account daylight savings time. I do not have pytz. Any ideas how to do it?

If it requires having pytz, how would I do it with pytz?

+1 vote

For a long time I have been doing:

/etc/locale.conf change: LANG="en_US.UTF-8"
LANG="en_GB.UTF-8"

To make Thunderbird list messages with 24 hour time. Can someone suggest a better way to accomplish this?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...