To install the Lock library in your project using Composer, first add the following to your composer.json
config file.
{
"require": {
"gielfeldt/lock": "~1.0"
}
}
Then run Composer's install or update commands to complete installation. Please visit the Composer homepage for more information about how to use Composer.
This lock handler ...
- "Easy" API (™)
- Separate storage logic to avoid boilerplate
- Ensure release on lock destruction
- Optionally persistent across requests
- Event handlers on e.g. release
- Force release (by non-owner)
namespace Gielfeldt\Lock\Example;
require 'vendor/autoload.php';
use Gielfeldt\Lock;
$lockService = new Lock\LockService([
'storage' => new Lock\Storage\Memory(),
]);
print "'mylock' is locked: " . $lockService->isLocked('mylock') . "\n";
print "Locking 'mylock'\n";
$lock = $lockService->acquire('mylock');
print "'mylock' is locked: " . $lockService->isLocked('mylock') . "\n";
$lock->bind('release', function ($lock) {
print "RELEASE EVENT 2: " . $lock->getName() . "\n";
});
$lock->release();
print "'mylock' is locked: " . $lockService->isLocked('mylock') . "\n";
For more examples see the examples/ folder.
- Use arbitrary storage backends for locks
- Persist locks across scripts
- Ensure release of locks on end-of-scope
- Attach custom event handlers on lock release
- Lots probably.