This behavior add concurrent lock on action controller. If lock acquire run same action again impossible.
- PHP 5.5.9 and later
- YII2 Framework
class SomeController extends Controller
{
public function behaviors()
{
return [
[
'class' => MutexBehavior::className(),
'mutex' => FileMutex::className(),
'annotationMark' => '@mark-mutex',
// 'mutexName' => string or callable
]
];
}
/**
* This action executed in any case
*/
public function actionWithouMutex()
{
// some do
}
/**
* This action not executed if already run
* @mark-mutex
*/
public function actionWithMutex()
{
// some do
}
}
composer install
./vendor/bin/phpunit
- trigger event if acquire lock fail
- configure mutex name