2017 © Pedro Peláez
 

library lock

Lock library.

image

gielfeldt/lock

Lock library.

  • Sunday, September 27, 2015
  • by gielfeldt
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Shutdown Handler

Build Status Test Coverage Scrutinizer Code Quality Code Climate, (*1)

Latest Stable Version Latest Unstable Version [Dependency Status][11] License Total Downloads, (*2)

[Documentation Status][12] [Documentation Status][12], (*3)

Installation

To install the Lock library in your project using Composer, first add the following to your composer.json config file., (*4)

{
    "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., (*5)

Lock

This lock handler ..., (*6)

Motivation/objectives

  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";
});

$lock->release();
print "'mylock' is locked: " . $lockService->isLocked('mylock') . "\n";

For more examples see the examples/ folder., (*7)

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

  1. Lots probably.

The Versions

27/09 2015

dev-master

9999999-dev https://github.com/gielfeldt/lock

Lock library.

  Sources   Download

MIT

The Requires

 

by Thomas Gielfeldt

lock mutex semaphore