worldnews — 2012-12-04T12:10:23-05:00 — #1
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?
kylewolfe — 2012-12-04T12:30:25-05:00 — #2
$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.
worldnews — 2012-12-04T15:48:18-05:00 — #3
I switched to time(); for getting $t1 & $t2, but I still see a difference of 0.000
between the 2!
kylewolfe — 2012-12-04T16:06:53-05:00 — #4
worldnews — 2012-12-05T00:02:47-05:00 — #5
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!
jeff_mott — 2012-12-05T01:54:53-05:00 — #6
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).
worldnews — 2012-12-06T00:00:52-05:00 — #7
That seems to work fine. That is microtime(true) results in more negative time diffs.