PHPackages                             sokolnikov911/console-mutex-updated - 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. [CLI &amp; Console](/categories/cli)
4. /
5. sokolnikov911/console-mutex-updated

ActiveLibrary[CLI &amp; Console](/categories/cli)

sokolnikov911/console-mutex-updated
===================================

Mutex for Laravel (including Laravel 10.x) Console Commands.

10.0.0(2y ago)02.2kMITPHPPHP ~8.1|~8.2

Since May 26Pushed 2y agoCompare

[ Source](https://github.com/sokolnikov911/laravel-console-mutex-updated)[ Packagist](https://packagist.org/packages/sokolnikov911/console-mutex-updated)[ RSS](/packages/sokolnikov911-console-mutex-updated/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (9)Versions (96)Used By (0)

[![Mutex for Laravel Console Commands](art/1380x575-optimized.jpg)](art/1380x575-optimized.jpg)

Laravel Console Mutex
=====================

[](#laravel-console-mutex)

Mutex for Laravel Console Commands.

LaravelConsole Mutex10.x[10.x](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/10.x)9.x[9.x](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/9.x)8.x[8.x](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/8.x)7.x[7.x](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/7.x)6.x[6.x](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/6.x)5.8.\*[5.8.\*](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/5.8)5.7.\*[5.7.\*](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/5.7)5.6.\*[5.6.\*](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/5.6)5.5.\*[5.5.\*](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/5.5)5.4.\*[5.4.\*](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/5.4)5.3.\*[5.3.\*](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/5.3)5.2.\*[5.2.\*](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/5.2)5.1.\*[5.1.\*](https://github.com/sokolnikov911/laravel-console-mutex-updated/tree/5.1)[![Laravel Console Mutex - Demo](doc/img/demo.gif)](doc/img/demo.gif)

Table of contents
-----------------

[](#table-of-contents)

- [Usage](#usage)
- [Strategies](#strategies)
- [Advanced](#advanced)
    - [Set custom timeout](#set-custom-timeout)
    - [Handle multiple commands](#handle-multiple-commands)
    - [Set custom storage folder](#set-custom-storage-folder)
- [Troubleshooting](#troubleshooting)
    - [Trait included, but nothing happens?](#trait-included-but-nothing-happens)
    - [Several traits conflict?](#several-traits-conflict)
- [Sponsors](#sponsors)
- [License](#license)

Usage
-----

[](#usage)

1. Install the package via Composer:

    ```
    composer require illuminated/console-mutex
    ```
2. Use `Illuminated\Console\WithoutOverlapping` trait:

    ```
    use Illuminated\Console\WithoutOverlapping;

    class ExampleCommand extends Command
    {
        use WithoutOverlapping;

        // ...
    }
    ```

Strategies
----------

[](#strategies)

Mutex can prevent overlapping by using various strategies:

- `file` (default)
- `mysql`
- `redis`
- `memcached`

The default `file` strategy is acceptable for small applications, which are deployed on a single server. If your application is more complex and deployed on several nodes, you should consider using another mutex strategy.

You can change strategy by using the `$mutexStrategy` field:

```
class ExampleCommand extends Command
{
    use WithoutOverlapping;

    protected string $mutexStrategy = 'mysql';

    // ...
}
```

Or by using the `setMutexStrategy()` method:

```
class ExampleCommand extends Command
{
    use WithoutOverlapping;

    public function __construct()
    {
        parent::__construct();

        $this->setMutexStrategy('mysql');
    }

    // ...
}
```

Advanced
--------

[](#advanced)

### Set custom timeout

[](#set-custom-timeout)

By default, if mutex sees that the command is already running, it will immediately quit. You can change that behavior by setting a timeout in which mutex can wait for another running command to finish its execution.

You can set the timeout by specifying the `$mutexTimeout` field:

```
class ExampleCommand extends Command
{
    use WithoutOverlapping;

    // In milliseconds
    protected ?int $mutexTimeout = 3000;

    // ...
}
```

Or by using the `setMutexTimeout()` method:

```
class ExampleCommand extends Command
{
    use WithoutOverlapping;

    public function __construct()
    {
        parent::__construct();

        // In milliseconds
        $this->setMutexTimeout(3000);
    }

    // ...
}
```

Here's how the `$mutexTimeout` field is treated:

- `0` - no waiting (default);
- `{int}` - wait for the given number of milliseconds;
- `null` - wait for the running command to finish its execution;

### Handle multiple commands

[](#handle-multiple-commands)

Sometimes it might be useful to have a shared mutex for multiple commands. You can easily achieve that by setting the same mutex name for all of those commands.

You should use the `getMutexName()` method for that:

```
class ExampleCommand extends Command
{
    use WithoutOverlapping;

    public function getMutexName()
    {
        return 'shared-for-command1-and-command2';
    }

    // ...
}
```

### Set custom storage folder

[](#set-custom-storage-folder)

If you're using the `file` strategy, mutex files would be stored in the `storage/app` folder.

You can change that by overriding the `getMutexFileStorage()` method:

```
class ExampleCommand extends Command
{
    use WithoutOverlapping;

    public function getMutexFileStorage()
    {
        return storage_path('my/custom/path');
    }

    // ...
}
```

Troubleshooting
---------------

[](#troubleshooting)

### Trait included, but nothing happens?

[](#trait-included-but-nothing-happens)

`WithoutOverlapping` trait overrides the `initialize()` method:

```
trait WithoutOverlapping
{
    protected function initialize(InputInterface $input, OutputInterface $output)
    {
        $this->initializeMutex();

        parent::initialize($input, $output);
    }

    // ...
}
```

If your command overrides the `initialize()` method too, you have to call the `initializeMutex()` method by yourself:

```
class ExampleCommand extends Command
{
    use WithoutOverlapping;

    protected function initialize(InputInterface $input, OutputInterface $output)
    {
        // You have to call it first
        $this->initializeMutex();

        // Then goes your custom code
        $this->foo = $this->argument('foo');
        $this->bar = $this->argument('bar');
        $this->baz = $this->argument('baz');
    }

    // ...
}
```

### Several traits conflict?

[](#several-traits-conflict)

If you're using another `illuminated/console-%` package, you'll get the "traits conflict" error.

For example, if you're building a [loggable command](https://github.com/dmitry-ivanov/laravel-console-logger), which doesn't allow overlapping:

```
class ExampleCommand extends Command
{
    use Loggable;
    use WithoutOverlapping;

    // ...
}
```

You'll get the traits conflict, because both of those traits are overriding the `initialize()` method:

> If two traits insert a method with the same name, a fatal error is produced, if the conflict is not explicitly resolved.

To fix that - override the `initialize()` method and resolve the conflict:

```
class ExampleCommand extends Command
{
    use Loggable;
    use WithoutOverlapping;

    protected function initialize(InputInterface $input, OutputInterface $output)
    {
        // Initialize conflicting traits
        $this->initializeMutex();
        $this->initializeLogging();
    }

    // ...
}
```

License
-------

[](#license)

Laravel Console Mutex is open-sourced software licensed under the [MIT license](LICENSE.md).

Forked from

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity92

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 98.5% 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

Every ~29 days

Recently: every ~167 days

Total

95

Last Release

851d ago

Major Versions

7.1.0 → 8.1.02020-12-21

6.x-dev → 7.x-dev2021-01-03

7.x-dev → 8.x-dev2021-03-04

8.x-dev → 9.0.02022-02-19

9.x-dev → 10.x-dev2024-01-10

PHP version history (13 changes)0.1.1PHP &gt;=7.0.0

0.1.2PHP &gt;=5.4.0

1.0.2PHP &gt;=5.5.9

1.1.6PHP &gt;=5.6.4

5.5.0PHP &gt;=7.0

5.6.0PHP ^7.1.3

6.0.0PHP ^7.2

7.0.0PHP ^7.2.5

8.0.0PHP ^7.3

6.2.0PHP ^7.2.5|^8.0

8.1.0PHP ^7.3|^8.0

9.0.0PHP ^8.0.2

10.x-devPHP ~8.1|~8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/97a1cefec9fcbf213bb9a2db1f26e21b6ccb750984727256dd9833c5b27f25ae?d=identicon)[sokolnikov911](/maintainers/sokolnikov911)

---

Top Contributors

[![dmitry-ivanov](https://avatars.githubusercontent.com/u/1286821?v=4)](https://github.com/dmitry-ivanov "dmitry-ivanov (391 commits)")[![dmirogin](https://avatars.githubusercontent.com/u/5470439?v=4)](https://github.com/dmirogin "dmirogin (2 commits)")[![mihan007](https://avatars.githubusercontent.com/u/939122?v=4)](https://github.com/mihan007 "mihan007 (1 commits)")[![rafacouto](https://avatars.githubusercontent.com/u/969061?v=4)](https://github.com/rafacouto "rafacouto (1 commits)")[![SBLAdam](https://avatars.githubusercontent.com/u/81582882?v=4)](https://github.com/SBLAdam "SBLAdam (1 commits)")[![sokolnikov911](https://avatars.githubusercontent.com/u/11427142?v=4)](https://github.com/sokolnikov911 "sokolnikov911 (1 commits)")

---

Tags

consolelaravelsemaphoremutexcommandlockermutex-lockno-overlapping

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sokolnikov911-console-mutex-updated/health.svg)

```
[![Health](https://phpackages.com/badges/sokolnikov911-console-mutex-updated/health.svg)](https://phpackages.com/packages/sokolnikov911-console-mutex-updated)
```

###  Alternatives

[illuminated/console-mutex

Mutex for Laravel Console Commands.

146938.2k1](/packages/illuminated-console-mutex)[nunomaduro/laravel-console-menu

Laravel Console Menu is an output method for your Laravel/Laravel Zero commands.

815412.0k48](/packages/nunomaduro-laravel-console-menu)

PHPackages © 2026

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