| Conditions | 3 |
| Paths | 3 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 24 | public function mutexReserve(string $userId, string $key) : false|\SysvSemaphore {
|
||
| 25 | if (!\extension_loaded('sysvsem')) {
|
||
| 26 | $this->logger->warning('PHP extension sysvsem should be installed to guarantee correct behavior');
|
||
| 27 | return false; |
||
| 28 | } |
||
| 29 | |||
| 30 | $mutexKey = self::SEMAPHORE_KEY_BASE + $this->cache->forcedGetId($userId, "mutex_key.$key"); |
||
| 31 | $mutex = \sem_get($mutexKey); |
||
| 32 | |||
| 33 | if ($mutex !== false) {
|
||
| 34 | \sem_acquire($mutex); |
||
| 35 | } else {
|
||
| 36 | $this->logger->warning('Failed to acquire the semaphore');
|
||
| 37 | } |
||
| 38 | |||
| 39 | return $mutex; |
||
|
|
|||
| 40 | } |
||
| 47 | } |