diff --git a/src/NinjaMutex/Lock/MemcachedLock.php b/src/NinjaMutex/Lock/MemcachedLock.php index 88a2051..269c770 100644 --- a/src/NinjaMutex/Lock/MemcachedLock.php +++ b/src/NinjaMutex/Lock/MemcachedLock.php @@ -115,9 +115,26 @@ public function releaseLock($name) * @param string $name name of lock * @return bool */ - public function isLocked($name) - { - return false !== $this->memcached->get($name); + public function isLocked($name) { + $value = $this->memcached->get($name); + if ($value) { + $values = unserialize($value); + // Additional verification, just in case the lock was acquired by a process that doesn't exist anymore + $informations = $this->generateLockInformation(); + $output = null; + // @todo the following command has only be tested on Debian8 & MacosX + exec("ps -p {$values[0]}", $output); + // If the original server is the same that the one we're on, but the process has gone, let's remove the LOCK from Memcache + if($informations[2] == $values[2] && (count($output) == 1)) { + $this->memcached->delete($name); + return false; + } else { + return true; + } + } else { + // Value doesn't exist, so there is no lock + return false; + } } }