1 | <?php |
||
17 | abstract class AbstractPool |
||
18 | { |
||
19 | /** |
||
20 | * process list |
||
21 | * |
||
22 | * @var Process[] |
||
23 | */ |
||
24 | protected $processes = array(); |
||
25 | |||
26 | /** |
||
27 | * get process by pid |
||
28 | * |
||
29 | * @param $pid |
||
30 | * @return null|Process |
||
31 | */ |
||
32 | 3 | public function getProcessByPid($pid) |
|
42 | |||
43 | /** |
||
44 | * shutdown sub process and no wait. it is dangerous, |
||
45 | * maybe the sub process is working. |
||
46 | */ |
||
47 | 3 | public function shutdownForce() |
|
51 | |||
52 | /** |
||
53 | * shutdown all process |
||
54 | * |
||
55 | * @param int $signal |
||
56 | */ |
||
57 | 9 | public function shutdown($signal = SIGTERM) |
|
65 | |||
66 | /** |
||
67 | * if all processes are stopped |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 3 | public function isFinished() |
|
80 | |||
81 | /** |
||
82 | * waiting for the sub processes to exit |
||
83 | * |
||
84 | * @param bool|true $block if true the parent process will be blocked until all |
||
85 | * sub processes exit. else it will check if there are processes that had been exited once and return. |
||
86 | * @param int $sleep when $block is true, it will check sub processes every $sleep minute |
||
87 | */ |
||
88 | 9 | public function wait($block = true, $sleep = 100) |
|
99 | |||
100 | /** |
||
101 | * get the count of running processes |
||
102 | * |
||
103 | * @return int |
||
104 | */ |
||
105 | 21 | public function aliveCount() |
|
116 | |||
117 | /** |
||
118 | * get process by name |
||
119 | * |
||
120 | * @param string $name process name |
||
121 | * @return Process|null |
||
122 | */ |
||
123 | 3 | public function getProcessByName($name) |
|
133 | |||
134 | /** |
||
135 | * remove process by name |
||
136 | * |
||
137 | * @param string $name process name |
||
138 | * @throws \RuntimeException |
||
139 | */ |
||
140 | public function removeProcessByName($name) |
||
151 | |||
152 | /** |
||
153 | * remove exited process |
||
154 | */ |
||
155 | public function removeExitedProcess() |
||
163 | |||
164 | /** |
||
165 | * return process count |
||
166 | * |
||
167 | * @return int |
||
168 | */ |
||
169 | 3 | public function count() |
|
173 | |||
174 | /** |
||
175 | * get all processes |
||
176 | * |
||
177 | * @return Process[] |
||
178 | */ |
||
179 | 3 | public function getProcesses() |
|
183 | } |