t-kanstantsin / yii2-action-lock-behavior
Allow run only one action instance at once
Installs: 387
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Type:yii2-extension
pkg:composer/t-kanstantsin/yii2-action-lock-behavior
Requires
- php: >=7.1
- ext-mbstring: ^7.1
- psr/log: ^1.0
- yiisoft/yii2: ^2.0.10
This package is not auto-updated.
Last update: 2025-10-26 11:03:03 UTC
README
Yii widget
Basic
Behavior allow deny multiple runs of same console application action (e.g. long time executing task initiated with cron) using yii\mutex\* package.
Lock source should be chosen carefully noting following:
-
yii\mutex\FileMutexsimple but can be used only with one docker container instance because its not possible determine if process still running or ended in another container. Requires only writable directory -
yii\mutex\DbMutexrequires db connection. May be used only with single database instance.
Example
Using mutex from global config:
public function behaviors(): array { return [ 'pid' => ActionLockBehavior::class, ]; }
Define mutex on-the-fly:
public function behaviors(): array { return [ 'pid' => [ 'class' => ActionLockBehavior::class, 'mutex' => [ 'class' => FileMutex::class, 'mutexPath' => \Yii::getAlias('@runtime/pid'), ], ], ]; }