Your premium source for custom modification services for phpBB

HomeForumsBlogMOD ManagerFAQSearchRegisterLogin

Comments February 26, 2008

Counting Queries in phpBB2

Filed under: Performance Tuning, phpBB — Dave Rathbun @ 11:21 pm Comments Off 

A standard footer for phpBB2 boards includes the copyright (of course, you would not leave that off, would you? ;-) ) and various other things. It does not include any page generation statistics. There are a couple of MODs that will do that, and most are quite simple. For example, to echo the number of queries that it took to generate the page is incredibly easy to do.

The reason for this is simple. The information needed is already being captured and stored. I just need to reference it and send it out to the template. A little research shows that inside the /db/mysql4.php code is this line:

var $num_queries = 0;

And then later on, the function sql_query() includes this code:


So each time a query is executed the counter is incremented. I am sure most of you know, but in case not, the ++ is shorthand for “plus one” in php. This means that this code:

$x = $x + 1;

is equivalent to this code:


But I digress. :) The point is that there is already a counter used to store the number of queries executed on a page. So to put this information in the footer, all I had to do was this:

$query_ctr = $db->num_queries;
'QUERY_CTR' => $query_ctr

And then of course in my overall_footer.tpl I include a reference to the {QUERY_CTR} value. So that’s all it takes to get the number of queries on a page. (Here’s a hint: if the number of queries on a page is over 30, you have too many. If it’s over 65, you realy have too many. If it’s over 100… well, there’s a reason why “pre-modded” boards are not supported at phpbb.com. This is one of them. :) )

Now that we have the number of queries, the next important step is to find out how long those queries took to execute. That’s the next post in this series.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress