• Hi. I have a WordPress multisite which works in several servers (in fact, it’s an autoscaling platform hosted at Amazon Web Services). I would like that whenever I delete the cache of one site (by the direct button or when I update a post), all the cache files across all the servers be deleted too. So I would like to know if there is an specific action or filter inside WP Super Cache which I could use to achieve this. Or maybe there is already a plugin which does this.

    Thanks.

Viewing 12 replies - 1 through 12 (of 12 total)
  • eltano343, normally you should have some kind of common storage that is shared between all the instances if you want that behavior. NFS technically works, but it’s not very fast.

    Having a big NAS is better but probably not an option with AWS. In the end, WPSC is not really built for that type of environment.

    You may want to look into using a Memcached server with Batcache or W3TC. WPSC also as a Memcached option I think, although I’m not sure how solid it actually is… Not a fun choice, but having a shared storage (in RAM or disk) is the best way to scale.

    Thread Starter eltano343

    (@eltano343)

    Thanks for the response. Finally, I modified the WP Super Cache plugin to propagate the cache refresh to the other servers.

    I added my function in wp_cache_clear_cache(), wp_cache_clean_cache() and wp_cache_page_update() and it seems to work fine.

    Cool, I’m sure that others would be interested by your findings because it is the easiest way to scale horizontally in my opinion.

    What kind of lag are you seeing between the moment when you modify the “master instance” (if there’s one) and the moment where everyone is back in sync again?

    Thread Starter eltano343

    (@eltano343)

    I tested the modification in production and it had to rollback it. It took too much time to run. I am gonna think in a different solution.

    Just curious: did you try to use Rsync on the cached directory?

    btw, why don’t you just let each client generate its own local cache? It may be intense on the DB, but if there’s a DB cache, it shouldn’t be so bad.

    Thread Starter eltano343

    (@eltano343)

    Finally, I just let each server generate its own cache file. I only modified the plugin to allow deleting the cache in all the servers when the user hits the button “Delete cache”.

    cool – that’s a nice trick. so you can delete the disk cache on all servers when you hit Delete Cache on one of them? How do you sync all that? Anyway, I’m glad this works for you.

    Thread Starter eltano343

    (@eltano343)

    I just modified the file wp-cache.php and added this code when the funcion wp_cache_clean_cache starts:

    if(empty($_GET['no_propagate_cache_clean']))
        @file_get_contents('http://xx.xx.xx.xx/wp-content/plugins/services.php?clean_cache=1&f=wp_cache_clean_cache&p1='.urlencode($file_prefix).'&p2='.($all ? '1' : '0'));

    That file, services.php, is in another server (outside the platform) which has the same wordpress installation than the servers in production. Ant it calls another file, called, multiserver.php, inside the wp-super-cache folder which does only the following:

    <?
    include dirname(__FILE__).'/../../../wp-config.php';
    
    $functions_allowed = array();
    
    //$functions_allowed[] = 'wp_cache_post_change';
    //$functions_allowed[] = 'wp_cache_clear_cache';
    $functions_allowed[] = 'wp_cache_clean_cache';
    
    if(in_array(@$_POST['f'], $functions_allowed))
        call_user_func($_POST['f'], @$_POST['p1'], @$_POST['p2']);
    ?>

    It’s not the perfect solution, but it works.

    Cool trick, I never heard of that before. Thanks.

    Hey eltano,

    I was interested in your solution for clearing cache across a multi-server setup with WP Super Cache.

    What does your services.php file look like, meaning how does it call multiserver.php and pass the values to execute the wp_cache_clean_cache function.

    Thread Starter eltano343

    (@eltano343)

    Hi Anthony. The services.php file simply loops over the list of IPs and call this file directly to the server. It is something like this:

    <?
    $context = stream_context_create(array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Host: www.example.com\r\n",
            'content' => 'f='.urlencode(@$_GET['f']).'&p1='.urlencode($_GET['p1']).'&p2='.urlencode($_GET['p2']))));
    
    foreach($ips as $ip)
        @file_get_contents('http://'.$ip.'/wp-content/plugins/wp-super-cache/multiserver.php?no_propagate_cache_clean=1', false, $context);
    ?>

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘WP Super Cache and multiple servers’ is closed to new replies.