sadi01/yii2-mutex-filter MutexFilter is an action filter that apply mutex on controller's actions.

Yii2 Mutex Filter

  1. Installation
  2. Usage

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
        ]
    ];
}
0 0
1 follower
1 downloads
Yii Version: 2.0
License: BSD-3-Clause
Category: Others
Developed by: Sadegh Shafii
Created on: Mar 24, 2022
Last updated: (not set)
Packagist Profile
Github Repository