PHPackages                             pteich/simplelock - 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. pteich/simplelock

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

pteich/simplelock
=================

A simple locking/semaphore library for PHP 5.3+ with different adapters. Prevents flooding and multiple execution of code parts.

013PHP

Since Dec 5Pushed 11y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Simplelock
==========

[](#simplelock)

Overview
--------

[](#overview)

A simple locking/semaphore library for PHP 5.3+ with different adapters. Helps to keep code thread safe and prevent flooding or multiple execution of time consumptive code that could otherwise break your application.

You can set locks for a specific time duration. Locks can also be autoreleased on script termination. This assures that a task can only executed once at a time.

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

[](#installation)

### With Composer

[](#with-composer)

Just add `pteich/simplelock` to your composer.json require:

```
"pteich/simplelock":  "dev-master"

```

### Without Composer

[](#without-composer)

Download archive from Github and expand it to a directory. There is no autoloader provided so you'll have to deal with it for your own. You can register Simplelock directory with your PSR-4 compatible autoloader.

Usage
-----

[](#usage)

```
// create apc adapter
$adapter = new \Simplelock\Adapter\Apc();

// create simplelock object using $adapter and use autounlock feature
$lock = new \Simplelock(
	$adapter,
	true
);

$ttl = 60; // seconds to lock
$mykey = 'my key'; // key for this lock

if (!$lock->locked($mykey)) {
	// lock now
	$lock->lock($mykey,$ttl);
	// do hard work here
}
```

Adapters
--------

[](#adapters)

First argumente if the Simplelock constructor is an adapter object. Supported adapters are:

- **mock** - unlock always, for testing purposes
- **file** - file backend, keeps semaphore files in configurable directory
- **apc** - apc backend, keeps values in memory

### APC Adapter

[](#apc-adapter)

No config must be provided. APC extension is required. Values are delete from memory on unlock.

### File Adapter

[](#file-adapter)

Provide an array with `path` key pointing to a valid directory to store semaphore files. This adapter deletes files on unlock.

Example:

```
$adapter = new \Simplelock\Adapter\File(array(
	'path' => __DIR__ . '/lock'
));
```

### Mock Adapter

[](#mock-adapter)

This adapter keeps everything always unlocked. Useful for testing or to disable locking at all without removing calls to Simplelock.

### Autounlock

[](#autounlock)

If true is provided as second parameter to the Simplelock constructor all locks are automatically released on script termination.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

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/25d2632e10c78718d95ee4249d34030572920bd5ab8aff919879fdfcae601f7b?d=identicon)[pteich](/maintainers/pteich)

---

Top Contributors

[![pteich](https://avatars.githubusercontent.com/u/7067763?v=4)](https://github.com/pteich "pteich (2 commits)")

### Embed Badge

![Health badge](/badges/pteich-simplelock/health.svg)

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

###  Alternatives

[wwwision/dcb-eventstore

Implementation of the Dynamic Consistency Boundary pattern described by Sara Pellegrini

2131.5k10](/packages/wwwision-dcb-eventstore)

PHPackages © 2026

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