edgarpe / lock
Locking library for acquiring exclusive locks.
This package's canonical repository appears to be gone and the package has been frozen as a result.
v1.0.0
2016-02-10 13:41 UTC
This package is not auto-updated.
Last update: 2019-08-28 19:07:57 UTC
README
Usage
Run only in one instance, do not wait for lock to become available:
$lock = new \EdgarPE\Lock\Lock(__FILE__);
if ($lock->acquire(false)) {
echo posix_getpid(), "\n";
}
Wait for lock to become available:
$lock = new \EdgarPE\Lock\Lock(__FILE__);
if ($lock->acquire(true)) {
echo posix_getpid(), "\n";
}
Synchronized PHP callable, something similar like Java synchronized methods:
$lock = new \EdgarPE\Lock\Lock(__FILE__);
$pid = $lock->synchronized(function () {
return posix_getpid();
});
echo $pid, "\n";