Forum Moderators: coopster

Message Too Old, No Replies

displaying number of queries

just a quick q

         

ahmedtheking

6:53 pm on Dec 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You know when you come across sites that are made from phpnuke or e107 for example, and you see 'Render time: 0.9862 second(s). DB queries: 62.' at the bottom of the page, how do they do that?

Shaman13

7:05 pm on Dec 30, 2004 (gmt 0)

10+ Year Member



If your looking for a way to benchmark your page loads here is a little snippet I picked up along the way. I use it to test my pages.

=================================
<?
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec*1000);
}
$time=getmicrotime();
echo "Page was generated in ".sprintf("%01.7f",((getmicrotime()-$time)/1000))." seconds.";
?>
================================

ahmedtheking

7:19 pm on Dec 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yea thats kinda the jist of it! is there one that anyone knows of that displays the database queries that were excecuted?

ergophobe

7:46 pm on Dec 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Coopster probably knows some built-in function that gives you a count of the number of queries, but your stuck with me for now.

I would run a counter in my database abstraction layer that would increment a static variable [us3.php.net] or session variable by one for every query sent.

Otherwise, if I just wanted to know for my own benefit, I would simply run the xdebug profiler and it would return the number of times my query function in my abstraction layer was called.

Both of these, of course, depend on having a DB abstraction layer in place. I don't know how you would do it otherwise.

If you use a pre-made abstraction layer like the one from PEAR or something, they may have a built-in variable.