1 | <?php |
||
19 | abstract class LockAbstract implements LockInterface |
||
20 | { |
||
21 | const USLEEP_TIME = 100; |
||
22 | |||
23 | /** |
||
24 | * Information which allows to track down process which acquired lock |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $lockInformation = array(); |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $locks = array(); |
||
34 | |||
35 | 2 | public function __construct() |
|
39 | |||
40 | 70 | public function __clone() |
|
44 | |||
45 | /** |
||
46 | * Try to release any obtained locks when object is destroyed |
||
47 | * |
||
48 | * This is a safe guard for cases when your php script dies unexpectedly. |
||
49 | * It's not guaranteed it will work either. |
||
50 | * |
||
51 | * You should not depend on __destruct() to release your locks, |
||
52 | * instead release them with `$released = $this->releaseLock()`A |
||
53 | * and check `$released` if lock was properly released |
||
54 | */ |
||
55 | 66 | public function __destruct() |
|
67 | |||
68 | /** |
||
69 | * Acquire lock |
||
70 | * |
||
71 | * @param string $name name of lock |
||
72 | * @param null|int $timeout 1. null if you want blocking lock |
||
73 | * 2. 0 if you want just lock and go |
||
74 | * 3. $timeout > 0 if you want to wait for lock some time (in milliseconds) |
||
75 | * @return bool |
||
76 | */ |
||
77 | 230 | public function acquireLock($name, $timeout = null) |
|
95 | |||
96 | /** |
||
97 | * @param string $name |
||
98 | * @param bool $blocking |
||
99 | * @return bool |
||
100 | */ |
||
101 | abstract protected function getLock($name, $blocking); |
||
102 | |||
103 | /** |
||
104 | * Information generate by this method allow to track down process which acquired lock |
||
105 | * . |
||
106 | * By default it returns array with: |
||
107 | * 1. pid |
||
108 | * 2. server_ip |
||
109 | * 3. server_name |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | 3 | protected function generateLockInformation() |
|
127 | |||
128 | /** |
||
129 | * Information returned by this method allow to track down process which acquired lock |
||
130 | * . |
||
131 | * @return array |
||
132 | */ |
||
133 | 134 | protected function getLockInformation() |
|
137 | } |
||
138 |