Web Hosting Talk







View Full Version : [PHP] # of queries executed in #.## seconds


Tekster
12-25-2005, 10:03 PM
Does anyone know how to get the # of queries your script is running per page. I've saw some scripts have that sentence at the bottom of their pages, however, I don't know how to get the information for the #'s Any suggestions?

azizny
12-25-2005, 10:13 PM
make a variable called $queries_numbers... and whenever you make a query increment it then show it on the bottom..

Peace,

Burhan
12-26-2005, 02:00 AM
Personally, I don't see the point of spitting that out. Who is it for? To me, its like those visible counters. Just html spam.

hehachris
12-26-2005, 08:58 AM
if u have a class::function or just a function written to replace mysql_query()
u can simply add a variable in the function and ++

Czaries
12-27-2005, 05:13 PM
The purpose is for optimization... When you're developing a site, it's good to know how many queries are being run for each page load - that way you can make sure to keep it to a minimum. As far as displaying them to everyone all the time, I do agree with you that it's completely useless.

Dan L
12-28-2005, 01:31 AM
Like azizny and hehachris said, most sites use a database class. In their query() function, they stick $this->queryCount + 1; in there. Then they create a function to return $this->queryCount and echo it later.

For the time, they just used microtime() to subtract the start time from the end time to create an interger.

Some quick Googling would give you answers.

I'm with fyrestrtr and Czaries, though--don't bother using it for show.

streaky
12-29-2005, 03:22 PM
Use abstraction and count / time the number of queries, and only output it when you're developing - makes it very easy for people making DoS attempts to see if they are killing your mysql server, same for exection time and load averages - only use them when you actually need the information