I'm just wondering, i know its a basic one, but whats the code or process of calculating howmany SQL Querys have been done to generate the page?
Example, some sites have the following at the footer of a page:
[ Load Time: 0.0004 Seconds ] - [ Queries Made: 12 ]
I think it would be useful on the early stages of my site so i can see witch pages make the most strain on the server and such.
Cheers,
Rich[/syntax]
Server Load Time and Database Query
Moderator: General Moderators
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
If I recall correctly, most sites do the query count by making use of their custom db functions. ex, db_query.
Or, at least, that's how I'd do it.
Code: Select all
function db_query($sql){
$GLOBALS['db_queries']++;
return mysql_query($sql);
}- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I do it in the query method of my database class (because I am not big on using globals).
For timing, have a look at microtime(). For counts, just set a counter in the query function/method you are using and increment it as needed. You can also have a look at the static keyword for PHP 4, which will hold its value in the function scope and allow incrementing of that value without the need for a global variable.
For timing, have a look at microtime(). For counts, just set a counter in the query function/method you are using and increment it as needed. You can also have a look at the static keyword for PHP 4, which will hold its value in the function scope and allow incrementing of that value without the need for a global variable.
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
If you are using the ADOdb Lite database abstraction layer you can include these at the end of your php code.
ADOdb Lite records all queries and execution times. There is even a debug console that will record how fast every query executed.
http://adodblite.sourceforge.net/debugconsole.php

It can even keep track of any failed queries.
Code: Select all
echo "Queries: " . $db->query_count . " - Time: " . sprintf("%01.4f", $db->query_time_total) . "<br>";http://adodblite.sourceforge.net/debugconsole.php

It can even keep track of any failed queries.