dev-master 2015-09-27 12:09 UTC

This package is not auto-updated.

Last update: 2024-04-13 15:23:18 UTC


Build Status Test Coverage Scrutinizer Code Quality Code Climate

Latest Stable Version Latest Unstable Version Dependency Status License Total Downloads

Documentation Status Documentation Status


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 ...


  1. "Easy" API (™)
  2. Separate storage logic to avoid boilerplate
  3. Ensure release on lock destruction
  4. Optionally persistent across requests
  5. Event handlers on e.g. release
  6. 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";

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


  1. Lots probably.