sadi01/yii2-mutex-filter

MutexFilter is an action filter that apply mutex on controller's actions.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

v1.0.0 2022-03-24 14:37 UTC

This package is auto-updated.

Last update: 2024-11-24 21:21:46 UTC


README

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
        ]
    ];
}