Optimizing performance for WordPress

Taking responsibility of your WordPress site by keeping it up to date to the latest version and managing it’s load on the server hosting it is just as important as the content you’re writing for it. Security updates, performance improvements and other bug fixes will help keep your site running smoothly, but there are a few other steps you can take to improve it’s performance.

Keeping WordPress in check:

First thing is to make sure your install is current. It’s amazing the number of sites that you can come across that are still running older versions even with great tools like the WordPress Automatic Upgrade plugin written by Keith Dsouza of Techie Buzz which is a very simple way to update your site. It will backup your sites files and database, download the latest version of WordPress, place the site in maintenance mode (a simple splash screen), de-activate all plugins, updates WordPress and then reactivates the plugins after you have clicked the upgrade link. This step is probably one of the most missed tasks in maintaining your WordPress site and remember we’re not just talking about performance improvements here, but also keeping it update to any available security patches and preventing exploits like adding spam or reading copies of your saved drafts.

Caching in WordPress:

After making sure you have the latest version installed using caching is one of the simplest ways to improve your sites load times and also help reduce its load on the server. Donncha O Caoimh’s WordPress Super Cache plugin is an improved version of the WP-Cache 2 plugin by Ricardo Galli Granda. One improvement is that unlike the WP-Cache 2 plugin Super Cache will actually create a static HTML page instead of still having some PHP calls when served from the cache. It will serve simple HTML without having to use any PHP as long as the user visiting the site is not logged in or has not posted a comment. If they have commented or are logged in and tries to load a cached page the normal WP-Cache function will serve the page, but one of the best features of this plugin is the “LockDown” button. This will prevent the cache files from being deleted when a new comment is made. So if you think a post of yours is going to get hit by Digg or Slashdot you can have the server ready for the traffic or simply enable this after noticing any high traffic.

Comment and Pingback Spam:

Besides being just plain annoying comment and pingback spam can actually increase the load generated by your site. First make sure you are using the Akistmet plugin that comes with WordPress, then take a look at the using the comment blacklist feature under Options > Discussion. This will help reduce the number of spam that finds its way into your comments and pingbacks, but we also want to prevent blatant spam from posting at all to keep your queue of stuff marked as such as low as possible. To do that you can add some additional lines to your sites .htaccess file that I found at Perishable Press. By adding the rule found at the previous link you can keep any spammer from directly calling the file wp-comments-post.php to post a comment. If you do find that you have a large number of items marked as spam (hundreds or more of pages when you got to Comments > Akismet Spam) keep in mind that Akismet will automatically delete messages marked as spam greater than 15 days old. Depending on how your sever is performing it’s possible you might see the site slow down while its deleting all of those items marked as spam (a little later I’ll show you a tool that will help see what is going on in the background).

Offload as much as possible:

Any images, videos, audio, CSS and JavaScript files that you are serving from your server increase the number of requests that the web browser makes each time it loads your site. The good thing is that there are some very simple alternatives to place these files on a different server that is configured especially to serve static files. Instead of just using the obvious services from Flickr and YouTube for images and videos you can also use services like Amazon’s S3 to serve the CSS and any JavaScript files that your site is using. Also take a look at any additional JavaScript that you are adding for statistics, ads, calendars or basically any other information your are adding to it that is not a post or page. Consider using a web statistics product that is hosted on a different server (Google Analytics) instead of one that is served from your site like Mint for example. Other web stats tools like AWStats and Webalizer don’t actually place any scripts on the site, but instead use the web servers access logs to generate the statistics, either of these tools would allow you to remove a call to any type of a webstats tool, but remember these are generally created from a scheduled job that is run and would not provide you with any type of real time reporting.

Pruning the Plugins:

If there are any plugins that you are not using you should deactivate and remove them from the wp-contents/plugins directory. After that take a close look at each plugin and try to determine the value your site gets out of it and what actually goes on in the background when the it is used. In the next section I’ll briefly go over a few tools that you can use, but remember to check both the WordPress Codex, forums and the plugins site as some of the question you’re about to ask may already been answered. If the plugin actually interacts with the database look at the number of queries that it is sending to it and try to determine if it using any type of caching or can be rewritten without using the database. If you are lucky enough to find a way to improve it’s performance make sure to submit a patch to the plugins author to allow others to benefit from your hard work.

How to see what is going on:

Here are a few tools you can use to see what is going on in the background on the web server your site is hosted on.

Firebug

A Firefox add-on giving you tools to edit, troubleshoot and view CSS, HTML and JavaScript in real time for a web page. Allowing you to see the load times and sizes of individual files (images, CSS and JavaScript) it can help pin down what is slowing down a site. And if you add the YSlow add-on from the Yahoo Developer Network it will integrate with Firebug to give you some feedback on your sites performance and some suggestions on how to improve things.

LiveHTTPHeaders

Another FireFox add-on LiveHTTPHeaders will display the http headers showing you any redirects, sessions, cookies, compression or caching that may be happening when viewing your site.

Mytop

To see what queries are running in your database you could use mytop which is similar to the Top command, but looks at MySQL instead. This tool would require that you have shell access and the ability to install it if it is not already there, but it’s a great way to see real time what your sites is asking the database for and to do.

Access / Error logs

Looking at your web servers access and error logs can give you a great deal of information. Being able to see any web server or PHP errors, where all of that traffic is coming from if the site starts to crawl to a halt from high traffic, if it is getting crawled or scraped by a bot, and can show suspicious activity. If you see a problem or suspect something unusual is happening these logs should be one of the first places you look.

Phpinfo

And don’t forget to take a look at how PHP is setup by using phpinfo. Create a file called phpinfo.php and enter only the following in it:

<?php

phpinfo();

?>

Save that and place it in your sites directory on the web server and you will be able to view the options, extensions, and a slew of additional information on PHP and the web server when you load the file in your web browser.

OK, that was a basic overview of some steps I take to optimize a WordPress site (or any site for that matter), but don’t forget another way to keep things humming along would be to consider actually hosting it on WordPress.com. Hopefully these steps will point you in the right direction to improving your site performance.

Advertisement
33 comments
  1. This is one of the most informative articles on WordPress performance optimization that I have seen in a long time. Very well constructed and presented — definitely suitable for future reference and further investigation. Thanks for the ping — I may not have had the pleasure otherwise ;)

  2. michaelb said:

    Thanks Jeff!

  3. Pingback: Links 26-01-2008

  4. Suresh said:

    I have a question, should we allow ping back to other sites, if yest how its useful. If you have answer of this question, I would like to know.

    thanks

  5. Excellent article!

    Thanks for the information.

  6. Leandro said:

    great post, very helpfull info

  7. Blagovest said:

    Check out the recently launched WP-Offload plugin. You will see a dramatical speedup especially if your posts have a lot of static content (images, documents, movies, etc.). It will completely redirect all the requests for static content to external cache servers, so the load on your web server will decrease significantly.

  8. Great! I’m defenitely going to try the WordPress Super Cache plugin. Thanks!

Follow

Get every new post delivered to your Inbox.