Quantcast
Channel: Live News for Yii Framework
Viewing all articles
Browse latest Browse all 2941

[extension] sadi01/yii2-mutex-filter

$
0
0

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

Viewing all articles
Browse latest Browse all 2941

Trending Articles