Guide To Optimizing WordPress Servers


After moving hosts for some reason my WP-Cache2 plugin stopped caching pages and I couldn’t work out why, so I’ve spent the last couple of hours looking for alternatives as I wanted to make sure I don’t get into trouble again with my new host, even though I have a VPS now rather than a shared host. I’ve managed to implement some good actions this morning which have significantly improved the page loading times of my WordPress blog. I’m sharing what I’ve done below which will definitely help other Wordpress users and other users who have to manage a server, get faster loading times as well as reducing server strain. Much needed, particularly if you make it onto Digg’s homepage!

Install APC Part I

The first action I implemented was installing Alternative PHP Cache or APC. APC speeds up loading times by caching compiled WordPress PHP files so that the loading time the next time a page is loaded is much faster. This is different to WP-Cache2, which stores the HTML of a page for a user-defined period, which can cause problems if new comments or posts are made within this period i.e. if the page changes. APC doesn’t suffer from this problem and all page loads are dynamic.

APC and WP-Cache2 currently can’t be installed at the same time, although Mark Jaquith is working on trying to get the best of both worlds by finding a way to get APC and WP-Cache2 to work together, and I’m pretty sure he will crack it soon. However, given that I can’t even get WP-Cache2 to work by itself I didn’t even attempt to try some of Mark’s experiments. Initially I struggled to install APC as until two weeks ago when I moved from Blogware to Wordpress I’d never even used MySQL before, much less configured a server. Luckily I found these instructions by Matthew Carroll on how to install APC which I almost managed to complete by myself, but Matthew was kind enough to finish the job for me.

Install APC Part II

Although my pages were loading faster after installing APC, Matthew and I were a bit disappointed by the speed as we were expecting more of a speed boost. I did a bit more digging around on the net and I found an old post by Mark Jaquith on WP-Hackers. Mark had been as enterprising as ever and had posted a custom script that uses APC as the object cache backend instead of WP’s default of caching objects to the disk. Once I installed this script my WordPress installation started to take full advantage of the APC installation and my pages literally started to fly, despite my 40-50 plugins. To install the script just rename it to object-cache.php and install it in wp-content/object-cache.php

Turn On MySQL Query Cache

MySQL 4 includes a query cache which helps if the database is running the same query over and over again on the same data set i.e. a page hasn’t changed; it is just being viewed over and over again. If the query cache is turned on MySQL can cache the result set, avoiding the overhead of repeatedly running the query. If you are on a shared server and you are public enemy number 1 for hogging database resources then this little beauty could be for you. Most decent hosts will probably have the MySQL qcache turned on by default, but it’s worth checking it just to be sure.

Post-Query Accelerator

Despite getting a significant speed increase from installing APC and also turning on MySQL’s query cache, I still wasn’t satisfied and I wanted more speed. The next optimisation step I found again came from Mark Jacquith in the form of the Post-Query Accelerator, which ensures that WordPress gets the most out of MySQL’s Query Cache. Here’s how it works in Mark’s own words:

WordPress’ post queries always ask for posts with post_date_gmt <= ‘$now’ where $now is set to the current time, to prevent posts in the future from showing up. This means that $now changes with each page load. For high volume MySQL sites, the system administrator might turn on MySQL’s qcache, in order to cache some SQL queries. The problem with $now is that it changes each time, so the query is never exactly the same again, and the cache doesn’t help. This plugin is designed to freeze $now to reflect the time of the most recent post or page. This does the job of preventing future posts from showing up, but doesn’t needlessly change $now on every load. This can lead to rather large query speedups on high volume sites or sites with many posts. If things like qcache and my.cnf are Greek to you, please don’t use this plugin. Those who need this plugin will know that they need it, and without a properly configured my.cnf with query caching, it will do nothing.

Installing the plugin couldn’t be easier. Just download and save the file named post-query-accelerator.php. Upload it to your /wp-content/plugins/ directory and activate it

Bookmark & Share

Related Posts

About the Author

author photo

Everton is based in London and has worked in the internet and mobile space for over ten years now, and before that worked in corporate strategy and consulting. He has a degree in Economics from Cambridge University, and currently runs the Portal and online operations for one of the largest ISPs in the UK. He also writes for Windows 7 News.

See All Posts by This Author

There Are 19 Responses So Far. »

Pages: « 2 [1] Show All

  1. #10

    Not that I can remember Mahmood

  2. #9

    Ah, thank you I read and implemented that already. I was wondering if there are any other settings that should be in the [apc] section of the php.ini file?

    Get well soon though! And thanks once again for this excellent article which helped a lot.

  3. #8

    You’re lucky Mahmood as I’m home today as I’m not well.

    To get APC and WP-cache to work together you only need to change one line - read more here

  4. #7

    Thank YOU Everton for the resources you provided. I shall keep WP2 on for a few days to evaluate the site’s speed then switch it off to compare and make a decision then.

    If you’re still around, can you please let me know what you actually put in the [apc] section of the php.ini file? I’ve just put the wp-cache-config as instructed, but should there be any other things in there or should APC be left at default values?

  5. #6

    [...] http://www.connectedinternet.co.uk/2006/06/18/945/ [...]

  6. #5

    [...] Guide To Optimizing WordPress Servers [...]

  7. #4

    [...] Guide to Optimizing WordPress Servers [...]

  8. #3

    [...] From: Guide To Optimizing WordPress Servers » Connected Internet [...]

  9. #2

    Nice roundup.
    You should mention that Mark Jacquith’s Post-Query Accelerator won’t be needed in 2.1 though the mainstream folks are many months away from that, certainly not this year with over 250 tickets in the trac system.

    Only other thing I know of, to add to your list, is to turn on the little mysql summary that Wordpress has via Jerome’s Query Diagnostics http://vapourtrails.ca/downloads/jeromes-query-diagnostics.zip
    which writes a summary of all the select calls at the end of your page footers (commented out, just do a view source) and see if any are taking an usual amount of time.

  10. #1

    [...] Guide To Optimizing WordPress Servers » Connected Internet: The latest tech news (tags: apache MySQL server wordpress) [...]

Pages: « 2 [1] Show All

Subscribe without commenting

Post a Response


Comment Policy: Any comments are permitted only because the site owner is letting you post, and any comments could be removed for any reason at the absolute discretion of the site owner.