I am having problems with memcache on my php site. Sometimes I get a report that the site is behaving badly, and when I look at memcache, I find that there are several keys on both cluster servers. Data does not match between two records (one older).
My understanding of memcached was that this should not happen ... the client must hash the key, and then always select the same server. Therefore, either my understanding is incorrect, or my code. Can someone explain why this could happen?
FWIW servers hosted on Amazon EC2.
All my memcache connections open with this function:
$mem_servers = array( array('ec2-000-000-000-20.compute-1.amazonaws.com', 11211, 50), array('ec2-000-000-000-21.compute-1.amazonaws.com', 11211, 50) ); function ConnectMemcache() { global $mem_servers; if ($memcon == 0) { $memcon = new Memcache(); foreach($mem_servers as $server) $memcon->addServer($server[0], $server[1], true); } return($memcon); }
and the values ββare saved through this:
function SetData($key,$data) { global $mem_global_key; if(MEMCACHE_ON_OFF) { $key = $mem_global_key.$key; $memcache = ConnectMemcache(); $memcache->set($key, $data); return true; } else { return false; } }
source share