returning time from MySQL select

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
calebsg
Forum Commoner
Posts: 28
Joined: Tue Jun 18, 2002 10:41 am

returning time from MySQL select

Post by calebsg »

How do I get the time that it takes for a MySQL SELECT statement to run? I need to be able to display it like: "Select query executed in x.xx seconds"

I already have a timer on how long it takes the page to load and would like one so that I can keep an eye on my queries. Well, that's the official reason. The real reason is I'm just curious :D
Matt Wade
Forum Newbie
Posts: 12
Joined: Sat May 04, 2002 7:47 pm

Post by Matt Wade »

Hmm..the only way I can think to do it off the top of my head is to use microtime()...something like :

function GetMicrotime() {
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

$starttime = GetMicrotime();
//do your query here
$endtime = GetMicrotime();
$totaltime = $endtime - $starttime;
echo 'Query executed in $totaltime seconds.";


Not perfect and the calculations and function calls do add a little bit in there. But, it will give you an estimate...
Post Reply