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

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

asinfotrack/yii2-semaphore
==========================

A lightweight semaphore component for the yii2-framework

1.0.0(6y ago)089[2 PRs](https://github.com/asinfotrack/yii2-semaphore/pulls)MITPHPPHP &gt;=7.0

Since Dec 16Pushed 2y ago2 watchersCompare

[ Source](https://github.com/asinfotrack/yii2-semaphore)[ Packagist](https://packagist.org/packages/asinfotrack/yii2-semaphore)[ RSS](/packages/asinfotrack-yii2-semaphore/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (4)Used By (0)

Yii2-semaphore
==============

[](#yii2-semaphore)

A lightweight semaphore component for the yii2-framework

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

[](#installation)

### Add dependency

[](#add-dependency)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require asinfotrack/yii2-semaphore
```

or add

```
"asinfotrack/yii2-semaphore": "~1.0.0"

```

to the `require` section of your `composer.json` file.

### Configuration

[](#configuration)

All you need to do is add the component config to your corresponding config file.

```
return [
    //...
    'components' => [
        //...
        'semaphore' => [
            //use the file based implementation
            'class' => \asinfotrack\yii2\semaphore\components\FileSemaphore::class,
            'lockFolderAlias' => '@runtime/semaphores',
        ],
        //...
    ],
    //...
];
```

Usage
-----

[](#usage)

The following example code shows how to work with the component within a console command. The two methods differ in the way the handle the case when a semaphore is taken already: the first method waits for the lock to become available, while the second doesn't. Without the second param of `acquire()` set to false, the lock is awaited.

For each semaphore you work with a string constant which can be freely defined. In this manner multiple semaphores can be used in parallel.

```
class SemaphoreDemoController extends \yii\console\Controller
{

    public function actionWaitForLock()
    {
        Yii::$app->semaphore->acquire('my-lock', true);

        //do the actual work

        Yii::$app->semaphore->release('my-lock');
    }

    public function actionSkipIfNotAvailable()
    {
        if (!Yii::$app->semaphore->acquire('my-lock', false)) {
            $this->stderr('Lock already taken');
            return ExitCode::UNAVAILABLE;
        }

        //do the actual work

        Yii::$app->semaphore->release('my-lock');
    }

}
```

Implementations
---------------

[](#implementations)

###### File based implementation

[](#file-based-implementation)

Class: `asinfotrack\yii2\semaphore\components\FileSemaphore`
Internally the component works with the php `flock()`-function. Therefore you have to keep in mind the [differences](https://www.php.net/manual/en/function.flock.php#refsect1-function.flock-notes) between the underlying operating systems.

Chagelog
--------

[](#chagelog)

###### [v1.0.0](https://github.com/asinfotrack/yii2-semaphore/releases/tag/1.0.0)

[](#v100)

- initial release
- main class in a stable condition

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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

2340d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/32196c480a4cca0724afc5982064d2f02aa2975f66e5bef343f7f72f6cefaf08?d=identicon)[asinfotrack](/maintainers/asinfotrack)

---

Top Contributors

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

---

Tags

semaphoreyii2component

### Embed Badge

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

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

###  Alternatives

[umanskyi31/opengraph

Created a new component for Yii2. The Open Graph component for your website

119.7k](/packages/umanskyi31-opengraph)[dlds/yii2-mlm

Yii2 Multi Level Marketing component

183.8k](/packages/dlds-yii2-mlm)

PHPackages © 2026

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