I like the web pages to be snappy, including my blog. I found my blog to be bit slow after I moved to WordPress even after performance tuning. After looking around for a solution I came across memcache back-end for WordPress object cache which can be downloaded from here. You have to drop the file object-cache.php into wp-content/. You will have to specify the memcached servers by adding the following lines to wp-config.php.
[sourcecode language=’php’]global $memcached_servers;
$memcached_servers = array(‘default’ => array(‘127.0.0.1:11211’));[/sourcecode]
My blog loaded faster than before, it was all good. Afterwards I wanted to install the memcache back-end for WP object cache on my mother’s blog using the same memcached server. I just dropped the wp-config.php file into my mother’s installation of WordPress. That’s when things became awry. My mother’s blog started to redirect to my blog π . After looking at wp-config.php closely it was clear to me it was designed for WordPress MU. However I didn’t want to give up on using memcache with WordPress. Looking even closer I noticed that I can specify the global variable $blog_id
and it would be perpended to the memcache object key. I added the following line to wp-config.php in my mother’s WordPress installation in addition to the two lines above and applied this patch (patched object-cache.php).
[sourcecode language=’php’]global $blog_id;
$blog_id = ‘priyani_mohanjith_net’;[/sourcecode]
That’s it, both my blog and my mother’s blog became fast and it was working without any issues. Hope this helps someone who wants to use the same memcached server with multiple installtions of vanilla WordPress. You cannot use this technique or memcache unless your blog is self hosted on a server where you have full control.
Using memcached with WordPress object cache
If you enjoyed this post, make sure you subscribe to my RSS feed!
Very good π i use in my site with wordpress blogs π
I need put memcached for restart server ?
I have problems with multiple blogs in the same server. I user blog_id variable but wp-admin don’t run correct.
I put memcache for carrero.es, herencia.net and decoracion2.com, and /wp-admin/ jump all time to the first access to carrero.es/wp-admin.
I put herencia.net/wp-admin and jump tu carrero.es/wp-admin … why ??
I need help :O now i desactivate memcache π
Please read the blog post. It’s all about the issue you are having.
Remove object-cache.php (just rename it).
this seems to work for multiple blogs in wordpress mu or multiple vanilla wordpress…
However this does not work with multiple installations of wordpress mu. Any way to get it to work instead of starting up another memcache server?
Mohanjith thank you man its working great!
Hey, I found your blog in a new directory of blogs. I dont know how your blog came up, must have been a typo, anyway cool blog, I bookmarked you. π
I’m Out! π
how install the parch?
I’m assuming your WordPress directory is named blog. Run the following command in the parent directory.
patch -p0 < object-cachephp.patch
thanks, but i need memcache in two domains different in the same server
You are not making much sense, do you want to use the same memcache server for two WordPress installations. Please read the post again, it is about using the same memcache server for two WordPress installations, whether it’s on two domains or not is insignificant.
ok, but the patch work in this case?
dont work with two installation of wordpress, the second installation in the the home page and others show in blank
LUis, if you applied the patch properly and made the other configuration changes it will work. I’m using the same memcached server for mohanjith.net/blog and priyani.mohanjith.net/blog and have no such issues. I did have similar issues without the patch.
Can you post your object-cache.php somewhere I can have a look?
which makes the patch?
I need to make manually changes, which makes the patch changes?
Can You post modified object-cache.php?
I’m using windows system and don’t have shell access to my webhost.
Updated the post with a link to patched file. For your convenience, https://www.mohanjith.net/blog/wp-content/uploads/2009/03/object-cachephp.txt
I get this error after following your instructions:
[Wed May 19 01:23:53 2010] [warn] mod_fcgid: stderr: PHP Parse error: syntax error, unexpected ‘}’ in /var/www/clients/client1/web9/web/wp-content/object-cache.php on line 74
any idea what could be wrong?
btw, I didn’t apply your patch as I think I don’t need it… I am trying to implement memcache just for one wpmu installation
Please see object-cache.php around line 74. You probably have an extra ‘}’
possibly, but the problem occurs with an unmodified version I got from here: http://wordpress.org/extend/plugins/memcached/
Could you spare a minute and have a look? I am not good with PHP…
Please follow the instructions given in the blog post, I do not maintain the plugin you mention. You might want to contact the plugin developer for help. As far as I know the plugin triggers a fatal error. If I get time I’ll create what’s discussed in this post to a plugin for everyones benefit π
Excellent Article! We’re now using memcache with WordPress sites and for our in-house Kaltura-CE install off one server. Thank you!
I setup memcache with another wordpress site running on an OS X server. Memcache is installed and running.. however the site now loads about 10s slower. If I change object-cache.php to object-cache.php_ the site instantly goes back to loading in just under 2s. Any idea why using the object-cache would slow the site down this much? Thanks!
It could be either because the key-value pairs are not being cached (or they are being removed from the cache due to memcached running out of memory) or network connection to the memcached server has very high latency. You should try to see why. Under normal circumstances using memcache (object-cache.php) will speed up page load time.