PHPackages                             dimarti/semaphore - 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. dimarti/semaphore

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

dimarti/semaphore
=================

Simple PHP Semaphore

v1.0.0(2y ago)06MITPHP

Since Jun 11Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/dimarti/semaphore)[ Packagist](https://packagist.org/packages/dimarti/semaphore)[ RSS](/packages/dimarti-semaphore/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Semaphore
=========

[](#semaphore)

A simple, dependency-free PHP semaphore based on a lock file.

Use it to prevent concurrent execution of a script — for example, to stop a cron job from overlapping with a previous run that hasn't finished yet.

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

[](#installation)

```
composer require dimarti/semaphore
```

Requires PHP 7.0+ (uses scalar type hints and `void` return types).

Usage
-----

[](#usage)

```
use Dimarti\Semaphore\Semaphore;

$semaphore = new Semaphore('/tmp/my-task.lock');

if ($semaphore->isLocked()) {
    exit("Another instance is already running.\n");
}

$semaphore->lock();

try {
    // ... do your work ...
} finally {
    $semaphore->unlock();
}
```

API
---

[](#api)

MethodDescription`__construct(string $lockfile)`Creates a semaphore bound to the given lock file path.`lock(): void`Creates the lock file and writes the current timestamp (`Y-m-d H:i:s`) into it.`unlock(): void`Removes the lock file.`isLocked(): bool`Returns `true` if the lock file exists, `false` otherwise.How it works
------------

[](#how-it-works)

The lock state is represented by the presence of a single file on disk:

- `lock()` writes the file (with a timestamp as its contents).
- `unlock()` deletes the file.
- `isLocked()` checks whether the file exists.

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance59

Moderate activity, may be stable

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

798d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5166798?v=4)[Diego](/maintainers/dimarti)[@dimarti](https://github.com/dimarti)

---

Top Contributors

[![dimarti](https://avatars.githubusercontent.com/u/5166798?v=4)](https://github.com/dimarti "dimarti (7 commits)")

### Embed Badge

![Health badge](/badges/dimarti-semaphore/health.svg)

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

###  Alternatives

[ronisaha/easy-bangla-date

Extended DateTime Class For Bangla Date and Time

328.5k](/packages/ronisaha-easy-bangla-date)

PHPackages © 2026

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