What is best way to get the time it took for Php MySQL to process a Query?
I am doing this currently:
1- When the Query is POSTED I set:
$t1 = $SERVER['REQUESTTIME'];
2- When the Query is done, that is after:
mysql_query($sql_chk_url) or die(mysql_error());
$t2 = $SERVER['REQUESTTIME'];
However, $t1 $t2 are always the same even though it takes like 5 seconds for the page to come back vs 1 second. etc.
What to do?
$SERVER['REQUESTTIME']; will display the time in which the request was made, not the current time... You could run a difference between that and time() at the very end of your script for a full page process time. Use time() before and after your query for your query process time.
I switched to time(); for getting $t1 & $t2, but I still see a difference of 0.000
between the 2!
I did as you suggested.
That is now I have at the start of the page:
$t1 = microtime();
and at the end of the page after the Query is down and the page generated:
$t2 = microtime();
however, some of the time I get a Negative value! What the HEK!
This should be super simple, but actually microtime requires a careful reading of the manual.
By default, microtime() returns a string in the form "msec sec" ... If get_as_float is set to TRUE, then microtime() returns a float
So microtime() is useless for any kind of math, and you should almost always use microtime(true).
That seems to work fine. That is microtime(true) results in more negative time diffs.
This topic is now closed. New replies are no longer allowed.