Discussion:
set_time_limit () - CPU time or elapsed time?
Tim Streater
2014-04-12 19:14:00 UTC
Permalink
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.



Tim Streater
Bedford House
Kake St
Waltham CT4 5RZ
01227 700322
Jim Giner
2014-04-12 20:06:22 UTC
Permalink
Post by Tim Streater
This function limits the"execution time" for a script. Is this CPU time or elapsed (wall-clock)
time?
Post by Tim Streater
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).
Post by Tim Streater
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?
Post by Tim Streater
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.
Post by Tim Streater
Tim Streater
Bedford House
Kake St
Waltham CT4 5RZ
01227 700322
Having made some coding errors that put me in a loop or some other
almost-endless process, I do believe that the time limit is cpu time.
My host uses a default of 30 secs and I have chosen to reset my .ini
file to be a 2 second default simply because that is quite a long time
in processing terms and I don't want something to tick away for 30
seconds of CPU time.

If you have a user whose scripts (a user writing their own scripts) I'd
say you might want to examine that logic. That - or you've got a hell
of a lot of number crunching going on.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tim Streater
2014-04-12 20:45:00 UTC
Permalink
Post by Jim Giner
Having made some coding errors that put me in a loop or some other
almost-endless process, I do believe that the time limit is cpu time.
My host uses a default of 30 secs and I have chosen to reset my .ini
file to be a 2 second default simply because that is quite a long time
in processing terms and I don't want something to tick away for 30
seconds of CPU time.
If you have a user whose scripts (a user writing their own scripts) I'd
say you might want to examine that logic. That - or you've got a hell
of a lot of number crunching going on.
Perhaps I didn't make it clear that the user is running my app - and hence is running the identical set of scripts that I'm running. I'm doing a fair bit with a number of SQLite databases - perhaps I need to add an index.
--
Cheers -- Tim
Stuart Dallas
2014-04-13 00:42:48 UTC
Permalink
Post by Tim Streater
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.
Post by Tim Streater
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.
Post by Tim Streater
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!
Post by Tim Streater
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.

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tim Streater
2014-04-13 09:51:00 UTC
Permalink
Post by Tim Streater
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!
Mmmm. Then I may need to disable it altogether for Windows. Inter alia, the scripts communicate with remote hosts, that may respond slowly, or have a lot to say. If all that time is going to be counted against the script ...

Thanks.
--
Cheers -- Tim
Continue reading on narkive:
Loading...