Interface Yiisoft\Mutex\MutexInterface
| Implemented by | Yiisoft\Mutex\Mutex |
|---|
The Mutex allows mutual execution of concurrent processes in order to prevent "race conditions".
This is achieved by using a "lock" mechanism. Each possibly concurrent process cooperates by acquiring a lock before accessing the corresponding data.
Usage example:
$mutex = new MyMutex('critical_logic');
if (!$mutex->acquire(1000)) {
throw new \Yiisoft\Mutex\Exception\MutexLockedException('Unable to acquire the "critical_logic" mutex.');
}
// ...
// business logic execution
// ...
$mutex->release();
Public Methods
| Method | Description | Defined By |
|---|---|---|
| acquire() | Acquires a lock. | Yiisoft\Mutex\MutexInterface |
| release() | Releases a lock. | Yiisoft\Mutex\MutexInterface |
Method Details
Acquires a lock.
| public abstract boolean acquire ( integer $timeout = 0 ) | ||
| $timeout | integer |
Time (in seconds) to wait for lock to be released. Defaults to zero meaning that method will return false immediately in case lock was already acquired. |
| return | boolean |
Whether a lock is acquired. |
|---|---|---|
public function acquire(int $timeout = 0): bool;
Signup or Login in order to comment.