Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- How to now the script execution time?
November 28, 2007, 6:32 pm
rate this thread
set_time_limit's php documentation:
"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."
So, subtracting the script's start-time from the script's end-time
wont give you the actual execution time but the total time spent on
doing everything the script did.
I need a way to know the real execution time so I can know how much
time is left for the script to execute. And depending on that, to make
decisions about whether to continue with the current task the script
is doing or to end the script if there is not enough time left.
Any idea would be apreciated.
Re: How to now the script execution time?
Simply use multiple checkpoints where you store microtime() in your
script. Place them at strategical places.
$myTimer = array();
// at start
$myTimer["start"] = microtime();
// before query1
$myTimer["beforeQ1"] = microtime();
// after query 1
$myTimer["afterQ1"] = microtime();
And at the end inspect $myTimer.
You can decide during the script if too much time is spend anywhere and
take appropriate action.
Hope this help.