note 96278 modified in function.memcache-add by danbrown

From: Date: Sat, 19 Jun 2010 03:51:56 +0000
Subject: note 96278 modified in function.memcache-add by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170263@lists.php.net to get a copy of this message
Race conditions happen on an heavy load server when more than one thread tries to execute memcache_add. For example if thread A and thread B try to save the same key you can test that sometimes both return TRUE. To have the right behaviour you can verify that the correct value is in the assigned key: <?php function memcache_safeadd(&$memcache_obj, $key, $value, $flag, $expire) { if (memcache_add($memcache_obj, $key, $value, $flag, $expire)) { return ($value == memcache_get($memcache_obj, $key)); } return FALSE; } ?> --was-- Race conditions happen on an heavy load server when more than one thread tries to execute memcache_add. For example if thread A and thread B try to save the same key you can test that sometimes both return TRUE. To have the right behaviour you can verify that the correct value is in the assigned key: <?php function memcache_safeadd(&$memcache_obj, $key, $value, $flag, $expire) { if (memcache_add($memcache_obj, $key, $value, $flag, $expire)) { return ($value == memcache_get($memcache_obj, $key)); } return FALSE; } ?> http://php.net/manual/en/function.memcache-add.php

« previous php.notes (#170263) next »