Before begin I've to warn the reader: watch out the d!

On a single web server (CentOS 6.3) using php-5.3.3 I've a bunch of unrelated wordpress sites (3.5), each one has its own DB (Mysql5.1) so the table_prefix is the same ("wp_").

To speep-up the wordpress I think to APC for the code and a memcache backend for the data, so on my web server I've compile & install libmemcached-1.0.15 and (using "pecl install") php-pecl-memcached 2.1.0 (pay attention to the ending "d"). As wp-plugin I used "memcached redux".

On two different servers (CentOS 6.3) I've compiled & installed memcached-1.4.15 backend daemon.

The Issue

First I login on wp.first-domain.com and everything is fine. When I try to log on on wp.second-domain.net I found myself redirect on wp.first-domain.com!

If I clean the memcached cache I can login on wp.second-domain.net, but then every other wp I try to login redirect me on wp.second-domain.net.

In my wp-config.php I use these settings:

// server list definition

// try to add a server-related prefix


IMHO the wp don't store the data with a significant prefix/salt so one blog fetch onother blog datas!

The work around

As workaround I've intalled the wp-plugin "Memcached Object Cache", that uses php-pecl-memcache (2.2.7) (note the missing "d") and the following code in config:


I think that I miss some set-up of memcached-redux but I don't exclude a missing functionality (or a bug).


Final goal is to use php-pecl-memcached, so my work around can be the solution.

1 Answer 1


If WordPress is using APC it will use it for its object cache, and since APC is per machine, not per cluster, the two will diverge, giving you problems if you're trying to run 1 site off of two machines.

In that scenario you will want 1 memcached deamon running, and configure your 2 servers to use the 1 instance.

But you mentioned 2 servers with unrelated sites.

So in this case, we have the same issue as here:


The plugin author says:

By default it should. But that requires that you use unique table prefixes (They all cannot be wp_).

To use it on many sites where the table prefixes are the same, you can add a constant to wp-config.php called WP_CACHE_KEY_SALT, such as:

define('WP_CACHE_KEY_SALT', md5(DB_NAME . FILE));

md5(DB_NAME . FILE) can be replaced by whatever you want, just as long as it is unique per site.

So in effect, you've already stumbled upon the solution for memcache, and the cause.

So perhaps, if you rename your table prefixes so that they're unique, memcached will work

To ellaborate, if we look at the memcachedredux plugins key method:

function key( $key, $group ) {  
    if ( empty( $group ) )
        $group = 'default';

    if ( false !== array_search( $group, $this->global_groups ) )
        $prefix = $this->global_prefix;
        $prefix = $this->blog_prefix;

    return preg_replace( '/\s+/', '', "$prefix$group:$key" );

and later in the constructor:

    global $blog_id, $table_prefix;
    $this->global_prefix = '';
    $this->blog_prefix = '';
    if ( function_exists( 'is_multisite' ) ) {
        $this->global_prefix = ( is_multisite() || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix;
        $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':';

Here we see that either the prefix is '' or it's the blog ID or the table prefix.

As such there is no handling of multiple sites -> 1 memcached. So change your table prefixes, test if it works. If it does not, then you will need to modify the plugin

  • My goal is to use the php-pecl-memcached extension, but memcached wp-plugin use php-pecl-memcache, so I miss my goal. Commented Jan 28, 2013 at 9:40
  • About APC, I did't install any plugin to use APC backend, so WP is not aware of it's presence and can't use it to store date (IMHO). Commented Jan 28, 2013 at 9:42
  • see modified answer, I was referring more to the unique table prefixes, clarified
    – Tom J Nowell
    Commented Jan 28, 2013 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.