PHPackages                             iainp999/lockman - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. iainp999/lockman

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

iainp999/lockman
================

Handlers for locked operations

v1.0(11y ago)620MITPHP

Since Sep 26Pushed 8y ago2 watchersCompare

[ Source](https://github.com/iainp999/lockman)[ Packagist](https://packagist.org/packages/iainp999/lockman)[ RSS](/packages/iainp999-lockman/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (3)Used By (0)

LockMan
=======

[](#lockman)

A generic locking library for PHP that uses named locks.

Locking is useful for controlling access to resources in a multi-process or distributed environment.

The idea is that the actual locking mechanism can be implemented in any way you like, in order to fit your technology stack. You would just need to implement `LockHandlerInterface` for a particular technology (there are example lock handlers provided for the local filesystem and the Drupal locking API).

You may have some offline processing involving multiple processes and shared resources, where guarantees about exclusive access to resources are required. In this case, you may want to look into using a library such as this, with an implementation of `LockHandlerInterface` that is appropriate for you.

See the examples of `LockHandlerInterface` implementations in `lib/LockMan/Handler`.

### Example Usage

[](#example-usage)

In this case, we assume that there is a class called `LockHandler` which implements `LockHandlerInterface`.

#### General

[](#general)

N.B. in reality, I would recommend using some configurable service/DI container for creating your objects.

```
$lockHandler = new LockHandler();
$lockable = new MyLockable();
if ($lockHandler->lock($lockable)) {
  // Some critical section code.
}
...

```

#### Locked Operation

[](#locked-operation)

You don't have to use this class, it's simply provided as a convenience for operations that require a lock to be acquired prior to their execution. The lock is released when the operation finishes; if an Exception occurs then the lock is released before the Exception is rethrown. An operation is any PHP callable.

The current implementation does not support the acquisition of multiple locks prior to execution. This may be supported in a future version.

What follows is a contrived example, you could, for example, construct many of these objects in a service container ('contrived' in that you probably wouldn't create all of these objects inline, as in this example).

```
$lockHandler = new LockHandler();
$lockedOperation = new LockedOperation($lockHandler);
$lockable = new MyLockable();
$myOperation = array('SomeClass', 'someMethod');
// Execute the locked operation.
try {
   $lockedOperation->execute($myOperation, $lockable);
}
catch (Exception $ex) {
   // handle exception.
}

```

One important thing to note here is that the $lockedOperation object can be re-used once created. The actual lock is defined by the instance of `LockableInterface` that is injected when the operation is executed.

The instance could be used, for example, inside a service container (such as the Symfony component) where the class that implements `LockHandlerInterface` could be defined in configuration and automatically injected into a lock handler 'service'.

Badges
------

[](#badges)

Travis CI : [![Build Status](https://camo.githubusercontent.com/d8702afb399117a00eedfcb49a92db5fc90f0a9f3d0b14cd7f887ab78438f236/68747470733a2f2f7472617669732d63692e6f72672f6961696e703939392f6c6f636b6d616e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/iainp999/lockman)Coveralls : [![Coverage Status](https://camo.githubusercontent.com/816486bbe612a5180db9db5cdc9c9b944e0dfc099b56e1f9dc9ebe021b1070f2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6961696e703939392f6c6f636b6d616e2f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/iainp999/lockman?branch=master)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4245d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/758722?v=4)[Iain Potter](/maintainers/iainp999)[@iainp999](https://github.com/iainp999)

---

Top Contributors

[![iainp999](https://avatars.githubusercontent.com/u/758722?v=4)](https://github.com/iainp999 "iainp999 (25 commits)")

---

Tags

lock

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/iainp999-lockman/health.svg)

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

###  Alternatives

[zerkalica/semaphore

This library provides an api for semaphore acquire and release

1119.0k1](/packages/zerkalica-semaphore)[nabao/laravel-lock

高性能, 分布式, 并发抢占锁, 队列锁

271.5k](/packages/nabao-laravel-lock)[pudongping/hyperf-wise-locksmith

A mutex library provider for the Hyperf framework, designed to enable serialized execution of PHP code in high-concurrency scenarios.

106.3k2](/packages/pudongping-hyperf-wise-locksmith)

PHPackages © 2026

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