| Conditions | 5 |
| Paths | 4 |
| Total Lines | 31 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | protected function doAcquireLock(string $name, int $timeout = null): bool |
||
| 30 | { |
||
| 31 | $lockFileName = $this->getLockFileName($name); |
||
| 32 | $payload = $this->getNewLockPayload($name); |
||
| 33 | |||
| 34 | $started = time(); |
||
| 35 | |||
| 36 | while(true) |
||
| 37 | { |
||
| 38 | if (!$this->storageDriver->exists($lockFileName)) |
||
| 39 | { |
||
| 40 | $this->storageDriver->write($lockFileName, $payload); |
||
| 41 | |||
| 42 | return true; |
||
| 43 | } |
||
| 44 | |||
| 45 | // timeout not reached: sleep another round and try againg |
||
| 46 | if ($timeout === null || ($started + $timeout) < time()) |
||
| 47 | { |
||
| 48 | sleep(3); |
||
| 49 | } |
||
| 50 | |||
| 51 | // timeout reached: return false |
||
| 52 | else |
||
| 53 | { |
||
| 54 | return false; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | return false; |
||
| 59 | } |
||
| 60 | |||
| 71 |