/** * Get exclusive mutex for key. Key will be still accessible to read and write, but * another process can exclude dog-pile effect, if before updating the key he will try to get this mutex. * @param mixed $key * @param mixed $auto_unlocker_variable - pass empty, just declared variable * @return bool */ public function lock_key($key, &$auto_unlocker_variable) { $r = $this->memcache->add($this->lock_key_prefix . $key, 1, null, $this->key_lock_time); if (!$r) { return false; } $auto_unlocker_variable = new KeyAutoUnlocker(array($this, 'unlock_key')); $auto_unlocker_variable->setKey($key); return true; }