We all love WordPress. But, honestly, it’s everything but fast. An easy way to speed it up a good deal is to make it use memcached for storing some of it’s data. And doing this is actually easier than one might think. There are some pre-requisites:
- Download and install libevent
- Download and install memcached
- Download and install the memcache extension for PHP
The first two follow the standard
route. For the third I suggest using
/path/to/your/php-install/phpize ./configure --enable-memcache make make install
Take note where the extension is intalled and have PHP load it by adding
to your php.ini. There’s a chance you’ll have to edit the line
, too, to reflect the actual path where the extensions can be found. After restarting PHP you should see the
extension in the output of phpinfo.
If everything is fine, we can add memcache support to our WordPress installation:
First, start your local memcached daemon using
memcached -d -l 127.0.0.1 -p 11211 -u nobody -m 64 -P /var/run/memcached/memcached.pid
This will give you 64 MByte of memcache storage which is more than enough for a single WordPress install.
Next, we have to make WordPress use that storage:
- Download the file object-cache.php from the WordPressÂµ site.
- Put it in your wp-content directory. Yes, that’s really wp-content
If you run just a single blog, you’re done now. In case you run multiple WordPress installations on your server, you should add something like this to your wp-config.php:
global $blogid; $blogid="some_identifier";
The identifier is absolutely yours to choose. I’d suggest to keep it short as not to waste your memcache storage with overly long keys.
If you inted to run more than one memcache instance, you may also need to add something like this to your wp-config.php:
global $memcached_servers; $memcached_servers = array('192.168.1.1:11211','192.168.1.2:11211');
Of course you’ll have to change the IP addresses given above to match your setup.
Using this setup I was able to cut the load time for this very site by half. Ymmv.