By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

How much execution time is left?

P: n/a
I'm using set_time_limit() to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?
Feb 8 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Mikhail Kovalev wrote:
I'm using set_time_limit() to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?
Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.

-thib´
Feb 9 '08 #2

P: n/a
thib´ wrote:
Mikhail Kovalev wrote:
>I'm using set_time_limit() to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?

Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.

-thib´
Not true.

set_time_limit is the limit for execution time. time() or microtime()
is real time. A huge difference.

For instance - say you have a time limit of 30 seconds. One second into
your script, a high priority process gets invoked and runs for two minutes.

You still have about 29 seconds left left on your script, but the time()
or microtime() function says you're 1 minute, 31 seconds over.

An extreme example, I know. But it gets the point across.

So no, there is no way to tell how much time is left.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Feb 9 '08 #3

P: n/a
..oO(thib´)
>Mikhail Kovalev wrote:
>I'm using set_time_limit() to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?

Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.
This won't work. In addition to Jerry's example a quote from the manual:

| Note: 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 outside the execution
| of the script such as system calls using system(), stream operations,
| database queries, etc. is not included when determining the maximum
| time that the script has been running.

Micha
Feb 9 '08 #4

P: n/a
Rob
On Feb 9, 3:42*pm, Michael Fesser <neti...@gmx.dewrote:
.oO(thib´)
Mikhail Kovalev wrote:
I'm using set_time_limit() to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?
Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.

This won't work. In addition to Jerry's example a quote from the manual:

| Note: 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 outside the execution
| of the script such as system calls using system(), stream operations,
| database queries, etc. is not included when determining the maximum
| time that the script has been running.

Micha
True, but in general terms, Thib's solution should work - unless
Mikhail knows beforehand that there will be a lot of non-PHP
processing going on, i.e. file transfers.

Rob.
Feb 11 '08 #5

P: n/a
Michael Fesser wrote:
.oO(thib´)
>Mikhail Kovalev wrote:
>>I'm using set_time_limit() to set maximum execution time. Is there a
way to check how much time is left at any time during the execution
itself?
Use time() or microtime() at the beginning of the script and store the
value. Later, call it again and substract the start time, you'll get the
elapsed time. Another substraction of the time limit by the elapsed time
will give you the remaining time.

This won't work. In addition to Jerry's example a quote from the manual:

| Note: 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 outside the execution
| of the script such as system calls using system(), stream operations,
| database queries, etc. is not included when determining the maximum
| time that the script has been running.

Micha
Good to know, thanks.

So, a not absolutely reliable way would be to stop the counter before every
'heavy' instruction and restart it again just after it, right?
I've seen some tiny handy "stopwatch" functions that could make the job
without too much complications.

Anyway, is it really worth it, Mikhail?

-thib´
Feb 13 '08 #6

P: n/a
There is a system resource call where PHP will admit how much system
time and user time has been used.

If you use lots of sleeps, freads, and cURLs, etc, you use very little
system time.

I have executed scripts on Godaddy websites [default CPU time 30
seconds] which are heavily waited, but the scripts are still
terminated after 15-20 minutes. I guess there is a dead-mans-handle.

Feb 19 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.