Download the PHP package yiisoft/mutex without Composer
On this page you can find all versions of the php package yiisoft/mutex. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yiisoft/mutex
More information about yiisoft/mutex
Files in yiisoft/mutex
Package mutex
Short Description Yii Mutex Library
License BSD-3-Clause
Homepage https://www.yiiframework.com/
Informations about the package mutex
Yii Mutex
This package provides mutex implementation and allows mutual execution of concurrent processes in order to prevent "race conditions".
This is achieved by using a "lock" mechanism. Each possibly concurrent processes cooperates by acquiring a lock before accessing the corresponding data.
Requirements
- PHP 7.4 or higher.
Installation
The package could be installed with Composer:
General usage
There are multiple ways you can use the package. You can execute a callback in a synchronized mode i.e. only a single instance of the callback is executed at the same time:
Another way is to manually open and close mutex:
It could be done on lower level:
And if you want even more control, you can acquire mutex manually:
Mutex drivers
There are some mutex drivers available as separate packages:
If you want to provide your own driver, you need to implement MutexFactoryInterface
and MutexInterface
.
There is ready to extend Mutex
, MutexFactory
and a RetryAcquireTrait
that contains retryAcquire()
method implementing the "wait for a lock for a certain time" functionality.
When implementing your own drivers, you need to take care of automatic unlocking. For example using a destructor:
and shutdown function:
Note that you should not call the exit()
or die()
functions in the destructor or shutdown function. Since calling
these functions in the destructor and shutdown function will prevent all subsequent completion functions from executing.
Documentation
- Internals
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Mutex is free software. It is released under the terms of the BSD License.
Please see LICENSE
for more information.
Maintained by Yii Software.