Memcache on multiple servers is safe to use from multiple http servers ?

From: Date: Tue, 18 Mar 2014 05:12:43 +0000
Subject: Memcache on multiple servers is safe to use from multiple http servers ?
Groups: php.general 
Request: Send a blank email to php-general+get-323065@lists.php.net to get a copy of this message
Hello, I am wondering if is safe to use memcache extension with multiple memcache servers used from multiple http/php servers ? I am asking this because I dont know how memcache extension is handling internally selecting the server where to get/set values. Because using multiple http servers I am not sure if for the same key all the http servers will query the same memcache server ? A sample from http/php server 1: $memcache = new Memcache; $memcache->addServer('memcache_host1', 11211); $memcache->addServer('memcache_host2', 11211); $memcache_obj->set('var_key', 'value A'); echo $memcache_obj->get('var_key'); A sample from http/php server 2: $memcache = new Memcache; $memcache->addServer('memcache_host1', 11211); $memcache->addServer('memcache_host2', 11211); $memcache_obj->set('var_key', 'value B'); echo $memcache_obj->get('var_key'); We can be sure both http/php servers 1 and 2 will set/get the var_key to the same memcache server ? Because otherwise it could be like this: 1. http server 1 is writing var_key to memcache_host1 2. http server 2 has an update and is writing updated var_key to memcache_host2 3. at a later time http server 1 is trying to get the var_key and is getting this from memcache_host1 => getting an outdated value ISSUE! So how safe is to use memcache extension with multiple memcache servers from multiple http/php servers ? Cristian

« previous php.general (#323065) next »