Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

399 Posts in 197 Topics- by 103 Members - Latest Member: AlohaJade

September 03, 2010, 02:01:32 PM
Support ForumAdministrationHow To'sWordpress: How to display the number of Queries and Page Generation Time
Pages: [1]   Go Down
Print
Author Topic: Wordpress: How to display the number of Queries and Page Generation Time  (Read 1064 times)
0 Members and 1 Guest are viewing this topic.
badkarma
god, root, no difference...
Jr. Member
**

Rep: 5
Offline Offline

Gender: Male
Posts: 89



View Profile WWW
« on: August 03, 2008, 11:50:43 PM »

This is a quick and dirty solution to help you sort of optimize your Wordpress Blog.
As you might know there are literally thousands of Wordpress plugins available, and unfortunately most of them
when added to your Wordpress installation will add a certain number of queries to the MySQL database for getting
their content.

Now, when it comes to querying database the saying "The more the merrier" isnīt exactly true. You should, for the sake of speed,
try to keep the queries to a minimum. To help you doing that it can be useful to have Wordpress tell you how much queries you thrust at the database when rendering your site. Wordpress offers a simple way to show how many queries are executed upon pageload to get all the required information from the database.

To activate that "feature" you need to edit a template of your Wordpress theme. Which template...depends on where you want that information to be shown. Usually it would be shown in the footer, i really canīt imagine any other place it would make sense but in the end thatīs up to you. Iīll just post the line of code that needs to be added for Wordpress to show some basic stats when the page is done loading.
Code:
<?php echo $wpdb->num_queries?> <?php _e('queries'); ?>. <?php timer_stop(1); ?> <?php _e('seconds'); ?>

Add this line of code to where you see fit in your template. I added it to the footer of my Blog, check the link in my signature to see it working and what sort of data it displays.

How is this helpful in troubleshooting performance ?
The more queries you execute the more stress you put on the MySQL server. Iīve seen Websites running Wordpress and doing slightly above 200 queries everytime a page is loaded. MySQL server sure wonīt find that funny. The less queries you use the faster your page will be rendered, as simple as that.

A clean Wordpress install will do about 20-30 queries each time a page is loaded, now go and add some plugins such as "Recent Posts", "Recent comments" and you will be at a 160 queries. Now imagine having 20 Users visiting your site at the same time. 20*160=3200 queries, which is a lot of stress for a MySQL server that is not dedicated to you but shared among a lot of other users that probably have Wordpress running as well, and use similar plugins. See where i am going with this ?
Considering you are on shared hosting, which means you have to share the available resources with other users hosting their website here as well it might make sense to keep an eye on the amount of resources you use. Though there are other measures that will help make your website load faster, such as using caching and serving static html files instead dynamic content, but checking MySQL queries has turned out to be a very important part of optimizing Wordpress.

Logged

With the idea that everyone should have a web presence no matter how old they are, where they live, and what they do, we are offering our service of PHP/MySQL script installation free of charge. Please visit
Register or Login
http://www.free-installations.info
for more information
Pages: [1]   Go Up
Print
Jump to:  

Theme orange-lt created by padexx