gielfeldt / lock
Lock library.
dev-master
2015-09-27 12:09 UTC
Requires
- php: >=5.4.0
- gielfeldt/shutdownhandler: ~1.0
This package is not auto-updated.
Last update: 2024-12-21 19:05:38 UTC
README
Installation
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.
Lock
This lock handler ...
Motivation/objectives
- "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)
Example 1 - using Lock library
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.
Features
- 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
Caveats
- Lots probably.