1 | <?php |
||
17 | class FileLock implements LockInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var string lock file |
||
21 | */ |
||
22 | protected $file; |
||
23 | |||
24 | /** |
||
25 | * @var resource |
||
26 | */ |
||
27 | protected $fp; |
||
28 | |||
29 | /** |
||
30 | * @var bool |
||
31 | */ |
||
32 | protected $locked = false; |
||
33 | |||
34 | /** |
||
35 | * create a file lock instance |
||
36 | * if the file is not exists, it will be created |
||
37 | * |
||
38 | * @param string $file lock file |
||
39 | * @return FileLock |
||
40 | */ |
||
41 | 12 | public static function create($file) |
|
45 | |||
46 | /** |
||
47 | * @param $file |
||
48 | */ |
||
49 | 12 | private function __construct($file) |
|
59 | |||
60 | /** |
||
61 | * get a lock |
||
62 | * |
||
63 | * @param bool $blocking |
||
64 | * @return mixed |
||
65 | */ |
||
66 | 9 | public function acquire($blocking = true) |
|
85 | |||
86 | /** |
||
87 | * release lock |
||
88 | * |
||
89 | * @return mixed |
||
90 | */ |
||
91 | 9 | public function release() |
|
107 | |||
108 | /** |
||
109 | * is locked |
||
110 | * |
||
111 | * @return mixed |
||
112 | */ |
||
113 | public function isLocked() |
||
117 | |||
118 | /** |
||
119 | * |
||
120 | */ |
||
121 | public function __destory() |
||
127 | } |