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.
>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. jstucklex@attgl obal.net
=============== ===
>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_t ime 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.
On Feb 9, 3:42 pm, Michael Fesser <neti...@gmx.de 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_t ime 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.
>>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_t ime 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.
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.
Comment