PHPackages                             gielfeldt/lock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gielfeldt/lock

ActiveLibrary

gielfeldt/lock
==============

Lock library.

09PHP

Since Sep 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/gielfeldt/lock)[ Packagist](https://packagist.org/packages/gielfeldt/lock)[ RSS](/packages/gielfeldt-lock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Shutdown Handler
================

[](#shutdown-handler)

[![Build Status](https://camo.githubusercontent.com/5f415b31c83debfb0ed17f0abd737a3541f90e3bfde5b01dc53a760683cfe095/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6769656c66656c64742f6c6f636b2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gielfeldt/lock/build-status/master)[![Test Coverage](https://camo.githubusercontent.com/f20168a50c1a8d66af7ba7a65cf0466a6a26325d3881cd1d416f4bb55b0a927f/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6769656c66656c64742f6c6f636b2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/gielfeldt/lock/coverage)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/565185f2a1589fa8737fc6a0c16efde5f8cbc90113dd319c60c69e62fa59f65d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6769656c66656c64742f6c6f636b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gielfeldt/lock/?branch=master)[![Code Climate](https://camo.githubusercontent.com/3e64880153b86c1ff92fc9c963d03f63a7b20e00a045571b0b5e7bd6415b9872/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6769656c66656c64742f6c6f636b2f6261646765732f6770612e737667)](https://codeclimate.com/github/gielfeldt/lock)

[![Latest Stable Version](https://camo.githubusercontent.com/bc480ed5f15e9c5fa6dc55203d4333536a9addaf9ef1854b18a3ba5353f1a15a/68747470733a2f2f706f7365722e707567782e6f72672f6769656c66656c64742f6c6f636b2f762f737461626c652e737667)](https://packagist.org/packages/gielfeldt/lock)[![Latest Unstable Version](https://camo.githubusercontent.com/1fd8dd15093cbdce85f4f9c96b08b994205edc49a511c30d7c2106b70b0b3e08/68747470733a2f2f706f7365722e707567782e6f72672f6769656c66656c64742f6c6f636b2f762f756e737461626c652e737667)](https://packagist.org/packages/gielfeldt/lock)[![Dependency Status](https://camo.githubusercontent.com/c61d86fcb58d3d7f87b3e5e8aff6c16d9c5511077478cb1a3b7cbd4f358c6f00/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3535666630633137363031646439303031633030303035382f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/55ff0c17601dd9001c000058)[![License](https://camo.githubusercontent.com/20bcc103fb86384c3ea39ac6257e1cd41e1d94b6341002a755ba5fdb333ecc00/68747470733a2f2f706f7365722e707567782e6f72672f6769656c66656c64742f6c6f636b2f6c6963656e73652e737667)](https://github.com/gielfeldt/lock/blob/master/LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/500468240140ae8d551195f70845c91f4b6591ec8b361f29e0072439935c9184/68747470733a2f2f706f7365722e707567782e6f72672f6769656c66656c64742f6c6f636b2f646f776e6c6f6164732e737667)](https://packagist.org/packages/gielfeldt/lock)

[![Documentation Status](https://camo.githubusercontent.com/47efee1516dd6f16b4d726f9c6cb372ea2513d39e124fe9fdea0e3310a9c7dd0/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f6c6f636b2f62616467652f3f76657273696f6e3d737461626c65)](https://readthedocs.org/projects/lock/?badge=latest)[![Documentation Status](https://camo.githubusercontent.com/17a6efc4ee3b0f2f4f5b3f4db3d8dac542bd385d975df24ef4ddaeb5b2898e69/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f6c6f636b2f62616467652f3f76657273696f6e3d6c6174657374)](https://readthedocs.org/projects/lock/?badge=latest)

Installation
------------

[](#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](http://getcomposer.org) for more information about how to use Composer.

### Lock

[](#lock)

This lock handler ...

#### Motivation/objectives

[](#motivationobjectives)

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

[](#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

[](#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

[](#caveats)

1. Lots probably.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e93f60ea3dd735998209863ed3e064b4aa440db3c23b08f44bf0655c28b0bd3c?d=identicon)[gielfeldt](/maintainers/gielfeldt)

---

Top Contributors

[![gielfeldt](https://avatars.githubusercontent.com/u/4096963?v=4)](https://github.com/gielfeldt "gielfeldt (22 commits)")

### Embed Badge

![Health badge](/badges/gielfeldt-lock/health.svg)

```
[![Health](https://phpackages.com/badges/gielfeldt-lock/health.svg)](https://phpackages.com/packages/gielfeldt-lock)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
