1 | <?php |
||
8 | class FileLock implements Lock |
||
9 | { |
||
10 | const EXCLUSIVE = true; |
||
11 | const SHARED = false; |
||
12 | |||
13 | const BLOCKING = true; |
||
14 | const NON_BLOCKING = false; |
||
15 | |||
16 | private $lock_file; |
||
17 | private $exclusive; |
||
18 | private $blocking; |
||
19 | private $fh; |
||
20 | private $remove_on_release; |
||
21 | |||
22 | private $logger; |
||
23 | |||
24 | /** |
||
25 | * @param string $lock_file path to file |
||
26 | * @param boolean $exclusive true for an exclusive lock, false for shared one |
||
27 | * @param boolean $blocking true to wait for lock to be available, |
||
28 | * false to throw exception instead of waiting |
||
29 | * @param boolean $remove_on_release remove file on release if no other lock remains |
||
30 | * @param LoggerInterface $logger |
||
31 | */ |
||
32 | public function __construct( |
||
46 | |||
47 | /** |
||
48 | * @inherit |
||
49 | */ |
||
50 | public function acquire() |
||
66 | |||
67 | /** |
||
68 | * try to acquire lock on file, throw in case of faillure |
||
69 | * @param int $operation |
||
70 | * @param string $lock_type lock type description |
||
71 | * @return void |
||
72 | * @see https://php.net/flock |
||
73 | */ |
||
74 | private function tryAcquire($operation, $lock_type) |
||
92 | |||
93 | public function release() |
||
111 | |||
112 | public function __destruct() |
||
116 | |||
117 | /** |
||
118 | * @return boolean |
||
119 | */ |
||
120 | private function flock($operation) |
||
132 | } |
||
133 |