Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display database query statistics on Wordpress site?

I've noticed that a few Wordpress blogs have query statistics present in their footer that simply state the number of queries and the total time required to process them for the particular page, reading something like:

23 queries. 0.448 seconds

I was wondering how this is accomplished. Is it through the use of a particular Wordpress plug-in or perhaps from using some particular php function in the page's code?

like image 923
Kit Roed Avatar asked Aug 18 '08 16:08

Kit Roed


2 Answers

Try adding this to the bottom of the footer in your template:

<?php echo $wpdb->num_queries; ?> <?php _e('queries'); ?>. <?php timer_stop(1); ?> <?php _e('seconds'); ?>
like image 176
pix0r Avatar answered Oct 08 '22 22:10

pix0r


To explain pix0r's code:

  • $wpdb->num_queries is the number of database queries.

  • _e is for localization: http://faq.wordpress.net/view.php?p=50

  • timer_stop() returns the amount of time taken to render the page:
    http://codex.wordpress.org/Function_Reference/timer_stop

like image 44
Carl Russmann Avatar answered Oct 08 '22 20:10

Carl Russmann