WordPress is one of the most popular blogging and CMS platforms to date.
What makes it unique is the fact that it satisfies the needs for both start-ups and very serious bloggers and businesses. The community is world class and you can get a very professional CMS and endless functional extensions for free.
WordPress sets new standards when it comes to support for building templates and it so easy to get started with and still so powerful that most people won’t let it go even if they run into serious success. Some of the really high traffic blogs out there run on WordPress! ex smashingmagazine, mashable that both have millions of hits every month.
But let me be honest with you – if your blog becomes just remotely popular you wont survive a standard out of the box WordPress deployment.[exec]$filestr = file_get_contents(‘http://www.tripwiremagazine.com/googleadsensebelowmoretag.inc’);
Flexibility, ease of use, etc. comes at a very high price and in fact WordPress consumes enormous amounts of CPU and memory resources in order to respond to a single page request. The many string replacements in templates, multiple request to the database per request simply adds up and may take your entire site down if you hit the front page on fx. digg.com. Of cause you can just buy more hardware but as most bloggers don’t have budget for that it is important to get as much as possible out of the hosting plan you have. For good order I would like to state that my experience tells me that if you start getting moderate traffic ex. more than 2500 hits per day then you have grown out of any shared hosting solutions no mater how much you optimize your WordPress installation! I learned this the hard way and ended up changing to a Hybrid VPS at Wired Tree. After experiencing the regular frustrations using a shared plan at bluehost.com (servers down, slow, account closed because of too much CPU usage etc. ) is one of the best experiences I have ever had as a blogger, seriously! I will not cover hosting any further in this blog as it is a subject of it own. Let’s investigate some essential tips you can use to improve you WordPress performance.
Measure load time for future reference
Before we optimize anything I would recommend that you collect a few measurements that you can use as reference to see if your actions to improve performance have been worth the effort. Take multiple measurements and if you have the time and patience try making measurements over a few days with varying load. Also keep in mind that plugins and themes are software and in some cases they may not be optimized too well. I recommend that you go for using premium wordpress magazine themes for my sites, also to get the support.
Option a) Goto this on-line speed test tool (or use similar) and make a few hit on your site. On-line services like “iwebtool Website Speed Test” is one way to get a measure but I would recommend you to use a client side tool as well to get a better picture of your actual performance.
Option b) Use YSlow for Firefox to analyse your template complexity, size and load time from a realistic client. The load time and size can be found in the lower right corner. The Yslow Grade will be covered later in this post but is worth investigating!
#1 – Use serious caching (impact: very high)
There are many ways to do caching in WordPress. I’ll be honest with you – I have a favourite way to do it! If you are not using WP Super Cache Plugin already this is the time to make the change. It generates fully static html files when your pages are accessed for the first time and these are then served directly by Apache without processing PHP scripts on subsequent requests. When you read on to the other tips below you will know why this is so important. Providing static cached html files as you will do with WP Super Cache Plugin is the single most effective performance optimization tip I can give you BUT it is not without problems. Some pages will contain dynamically generated content and you want your updates to pages to be visible to you readers instantly. So when serving static cached html you need an intelligent and very well integrated caching engine and that is just what I believe WP Super Cache Plugin is providing.
WP Super Cache Plugin serve static pages only to:
- Users who are not logged in.
- Users who have not left a comment on your blog.
- Or users who have not viewed a password protected post.
#2 – Optimize your template by reducing number of requests to the server, to the database and by lowering the overall load size (impact: very high)
Minimize simple unnecessary PHP queries. I’m a great fan of premium themes because they are so flexible and simple to adjust to your own needs. I also have found that flexibility is costly in terms of performance. To give you an example: searching for “bloginfo” in freshnews theme from Woothemes (the one I use) returns 283 results. What does this tell us? It tells us that functions like “bloginfo(‘name’)” and “get_bloginfo(‘template_directory’)” is used intensively. In some themes get_option() is also used heavily and will also be costly for rendering the page in the server. In the theme I have 961 of these… If you have cached your pages as described above this will only impact the first request where a page requested is not already cached. If user experience for all users (including the few who hit a non cached page) then it is highly relevant to see if you can get rid of any unnecessary PHP queries.
How to: ex. <?php get_bloginfo(’wpurl’); ?> just replace it with your wordpress installation URL.
#3 – Keep you database clean (impact: high)
Every database will, over time, require some form of maintenance to keep it at an optimal performance level. Purging deleted rows, resequencing, compressing, managing index paths, de-fragmenting, etc. is what is known as optimization. MySQL builds up what is called overhead and it will degrade your performance over time if you are not actively taking care of this. For good order you need to backup your database before the optimization procedure.
There are more ways to clean up overhead and repair your MySQL database. If you don’t have any database tools except for phpAdmin that most will have access to through their cpanel hosting admin interface. The phpAdmin way is rather simple and it is a tool you should be familiar with anyway. On the other hand it requires you to log into a separate tool and it would be much easier if you could do it all from WordPress – and you can. WP-DBManager is the perfect alternative and lets you do the database operation most WordPress user need including backups. It allows you to view current status of the database, optimize, repair, backup, restore, delete backup, drop/empty tables and run selected queries. Supports automatic scheduling of backing up and optimizing of database. Backing up and optimizing is as simple as clinking one button.
After running optimize all of your tables should have zero overhead as shown here. Check it once a month and run the job again when overhead starts building up.
If you are just like me – a bit lazy you may want to schedule all of this to happen automatically. In the DB Options tab you can configure this.
#4 – Proper image hosting can be important (impact: high)
#5 – Enable WP Built-in Object Cache (impact: medium)
WordPress introduced a file based caching of php objects in 2.x versions. It caches recurrently used php objects thereby reducing MySQL calls and improving performance.
It is currently disabled by default. You can enable it by adding the following to your wp-config.php:
// Enable the WordPress Object Cache:
This can give an immediate and measurable performance improvement. On the other hand it will increase the memory usage and you should be careful about using this on a shared hosting plan.
#6 – Turn off/limit/clean up post revisions (impact: medium)
Post revisions are important if you work together with others to create posts. It is also a good way to make sure that any changes to a post is documented and that something you have been working on for some time is not lost. On the other hand revisions can be a serious waste of database and server resources. Number of revision for a post can be found below the editing area.
To prevent the post revision from cluttering your database, it is an option to turn it off once and for all. You can easily turn off post-revision by adding the following line to the wp_config.php file (needs to be between the <?php and ?> tags.
This is that hard way and I would recommend another approach that prevents you from loosing any work if you fx. by accident save something wrong onto a document you put a lot of work into. You can keep a limited number of post revision saved per post. In your wp_config.php file, add the following line instead:
and replace the no_of_revision by the number of revision copy you want to keep.
If you used revisions for a long time and have hundreds of posts with 10+ revisions each you may want to consider cleaning this up and using the delete-revision plugin is a good option. It has not yet been fully tested with WP 2.8.6 but I have tried it as par of my preparations for this post and it worked fine.
#7 – Always keep WordPress and plugins up to date (impact: medium)
The developers maintaining WordPress are serious about their jobs and do a great job. Therefore it is recommended to plan an update as soon as WordPress informs you of a new release. With regards to upgrading performance may be the least of you concerns. Security is usually the top priority so even if your site is fast you should not wait too long with upgrades. Make sure to follow the backup advice in #2 before updating WordPress. Using the WordPress build in updating feature have worked fine for me every time. Just make sure that if you make any changes to core files in WordPress (even though you should not really) then updating this way will instantly overwrite your changes. Backing up your files and keeping track up custom changes is important in that case.
When it comes to plugins you should be very careful. Installing and activating a plugin that is not downloaded from wordpress.org may be a direct thread to you WordPress installation. Also make sure you check if a plugin is well rated (3 or more stars) on wordpress.org before using it. Some plugins are written by inexperienced programmers that may not have thought carefully enough about security and performance. It is important to do some investigations before trusting a plugin and to monitor your site performance carefully when new plugins have been installed. Believe me I have tried to have my account closed in my early days as a blogger because I activated a plugin that went bananas after a few days of operations because it used bad bad practise when querying the database.
#8 – Remove unused themes (impact: minor)
There is no reason to have a lot of unused themes on the server, delete those that you don’t use.
#9 – Disable and Delete unwanted plugins (impact: minor)
If you have decided that you have no use for a particular plugin, deactivate them and delete them from your server. The more (unused) plugins you keep in your server, the longer it takes for WordPress to generate the plugin list and the higher tendency that it will slow down the loading time of your blog. Simplest way to delete a plugin is by using the “Installed Plugins” page. Any plugin that is not active will have a delete button. Be aware that deleting a plugin this way will not clean up the database tables it used.
#10 – Delete spam comments (impact: minor)
If you get a lot of spam comments you should not leave it in the database. Make sure you delete it as it comes in. If you want to use a plugin to make cleaning up easier I can recommend WP-Optimize. It allows you to delete all spam and unapproved comments and provides a lot of other useful optimization features.
#11 – Check your site for dead links (impact: cosmetic)
In the blogging sphere linking to relevant content on other blogs and websites is common practice. To keep your posts relevant and useful you should check frequently that the linked post/domain still exist and you are not left with a dead link.
The broken link checker plugin checks your new article for broken links as soon as it is published. It also scans your old posts when you are logged into the Admin page. Any broken links found are reported to you and you can choose to edit or unlink them from the posts. The first time I used this plugin I found more than 250 broken links on old posts.
WordPress Performance: Why My Site Is So Much Faster Than Yours – This post is worth reading if you want to go even deeper into the details of optimization. It covers things you can do with regards to MySQL Query Cache, PHP Opcode Cache, Apache httpd.conf, PHP php.ini and Linux Kernel.