PHPackages                             alesinicio/mutex - 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. alesinicio/mutex

ActiveLibrary

alesinicio/mutex
================

Simple PHP Mutex implementation

1.0.0(1y ago)05PHPPHP &gt;=8.1

Since Oct 24Pushed 1y ago1 watchersCompare

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

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

MUTEX
=====

[](#mutex)

Simple PHP Mutex implementation.

Probably better suited for async applications where heavy-or-time-sensitive processes are executed in parallel with no intercommunication, and you need to implement some kind of semaphore.

Uses any PSR-16 (SimpleCache) implementation as the storage mechanism, just be sure to use something that all processes can access (in the likes of APC, memcached, Redis, plain files, etc...).

EXPLANATION
===========

[](#explanation)

Mutexes are based on named `events` and `timeouts`. You `lock` an `event` for a certain period of time (or forever, if you wish), and then you can check elsewhere if that same event is locked or not, and act accordingly. Usually, your first process will `lock` the event just before you start doing some important operation, and `unlock` the event when you are finished. And then other processes that should wait for the first process to finish will check whether that event is `locked` and wait until it is clear to proceed.

BASIC EXAMPLE
=============

[](#basic-example)

```
