473,395 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How much execution time is left?

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
6 4503
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
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
..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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to...
5
by: Johannes Lebek | last post by:
Hi there, lately, I experienced a strange thing on my DB2 V8.1 on Windows: Some queries took a very long time. A snapshot discovered the following: Number of executions = 47...
1
by: UnixSlaxer | last post by:
Hello all, I installed the trial version of DB2 UDB 8.2, I was wondering, how can I determine the exact execution time (in miliseconds not timerons) for a specific query ? Thank you very...
7
by: Tim Quon | last post by:
Hi Is there any function to get the current time so I can calculate the execution time of my code? What all is in the time.h and sys/times.h? Thanks Tim
38
by: vashwath | last post by:
Might be off topic but I don't know where to post this question.Hope some body clears my doubt. The coding standard of the project which I am working on say's not to use malloc.When I asked my...
3
by: iam980 | last post by:
Hello All. We have tested following SQL script from query analyzer: -- Script begin DECLARE @I int; SET @I = 1; WHILE @I < 10000000 BEGIN SET @I = @I + 1; END -- Script end
3
by: vashwath | last post by:
Hi all, I have written program for calculating the execution time of a function.Any critics (on the method of calculating execution time) are welcome. #include <stdio.h> #include <time.h>...
6
by: monkeyboy | last post by:
Hello, I have a function that hotshot says is very slow. I can get the aggregate execution time, but is there a way to get the execution time of each line so I can find the bottleneck? Thank...
25
by: Umesh | last post by:
i want to calculate the time required to execute a program. Also i want to calcute the time remaining for the execution of the program. how can i do that? pl mention some good websites for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.