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. Email us for help if needed.
Installs: 149
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/edgarpe/lock
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";