Yii2 Mutex Filter ¶
MutexFilter is an action filter relies on Yii2 Mutex component that apply mutex on controller's actions.
The Mutex component allows mutual execution of concurrent processes in order to prevent "race conditions". See Yii2 Mutex document.
Installation ¶
The preferred way to install this extension is through composer.
Either run console command
composer require sadi01/yii2-mutex-filter "*"
Or add the package to the require
section of your composer.json
file:
{
"require": {
"sadi01/yii2-mutex-filter": "*"
}
}
then run composer update
.
Usage ¶
Config Yii2 Mutex component
[
'components' => [
'mutex' => [
'class' => 'yii\mutex\FileMutex'
],
],
]
Then, simply use MutexFilter in your controller's behaviors :
public function behaviors()
{
return [
'mutexFilter' => [
'class' => \sadi01\mutexFilter\MutexFilter::class,
'mutexKeyPostfix' => 'anyString', // Optional
'exceptActions' => ['index', 'view'] // Exclude some actions
]
];
}
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.