Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release lock if the originating process is gone #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/NinjaMutex/Lock/MemcachedLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}