Last active
August 4, 2016 03:24
-
-
Save shoaibali/6908e3591fc87119619d to your computer and use it in GitHub Desktop.
SilverStripe memcached multiple servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Other useful changes and commands | |
// watch "echo stats | nc 127.0.0.1 11211" | |
// session.save_handler = memcache | |
// session.save_path = "tcp://server1:11211,tcp://server2:11211" | |
// $cache = SS_Cache::factory('foo'); | |
// $cache->clean(Zend_Cache::CLEANING_MODE_ALL); | |
if (defined('MEMCACHE_SERVER_1') && defined('MEMCACHE_PORT_1')) { | |
$servers = array( | |
'host' => MEMCACHE_SERVER_1, | |
'port' => MEMCACHE_PORT_1, | |
'persistent' => true, | |
'weight' => 1, | |
'timeout' => 5, | |
'retry_interval' => 15, | |
'status' => true, | |
); | |
} | |
if (defined('MEMCACHE_SERVER_2') && defined('MEMCACHE_PORT_2')) { | |
$servers = array( | |
'host' => MEMCACHE_SERVER_2, | |
'port' => MEMCACHE_PORT_2, | |
'persistent' => true, | |
'weight' => 1, | |
'timeout' => 5, | |
'retry_interval' => 15, | |
'status' => true, | |
); | |
} | |
if (!empty($servers)) { | |
SS_Cache::add_backend( | |
'primary_memcached', | |
'Memcached', | |
array( | |
'servers' => array($servers), | |
'compression' => true, | |
'compatibility' => false, | |
) | |
); | |
SS_Cache::pick_backend('primary_memcached', 'any', 10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment