@@ -20,7 +20,7 @@ |
||
20 | 20 | public function toArray() |
21 | 21 | { |
22 | 22 | return array_map( |
23 | - function ($fork) { |
|
23 | + function($fork) { |
|
24 | 24 | return $fork->getResult()->getReturn(); |
25 | 25 | }, |
26 | 26 | $this->forks |
@@ -49,7 +49,7 @@ |
||
49 | 49 | $type, |
50 | 50 | $pid, |
51 | 51 | ($this->ownerPid === $pid) ? 'p' : 'c', |
52 | - $message . PHP_EOL |
|
52 | + $message.PHP_EOL |
|
53 | 53 | ) |
54 | 54 | ); |
55 | 55 | } |
@@ -50,15 +50,15 @@ |
||
50 | 50 | } |
51 | 51 | $pid = getmypid(); |
52 | 52 | switch (true) { |
53 | - case $this->ownerPid === $pid: |
|
54 | - $role = 'owner'; |
|
55 | - break; |
|
56 | - case $this->masterPid !== null && $this->masterPid === $pid: |
|
57 | - $role = 'master'; |
|
58 | - break; |
|
59 | - default: |
|
60 | - $role = 'worker'; |
|
61 | - break; |
|
53 | + case $this->ownerPid === $pid: |
|
54 | + $role = 'owner'; |
|
55 | + break; |
|
56 | + case $this->masterPid !== null && $this->masterPid === $pid: |
|
57 | + $role = 'master'; |
|
58 | + break; |
|
59 | + default: |
|
60 | + $role = 'worker'; |
|
61 | + break; |
|
62 | 62 | } |
63 | 63 | fputs( |
64 | 64 | $this->destination, |
@@ -28,7 +28,7 @@ |
||
28 | 28 | { |
29 | 29 | $this->ownerPid = $ownerPid; |
30 | 30 | $this->concurrency = $concurrency; |
31 | - $this->ipcKey = new IpcKey($ownerPid, 'snidel_token_' . uniqid((string) mt_rand(1, 100), true)); |
|
31 | + $this->ipcKey = new IpcKey($ownerPid, 'snidel_token_'.uniqid((string) mt_rand(1, 100), true)); |
|
32 | 32 | $this->id = msg_get_queue($this->ipcKey->generate()); |
33 | 33 | $this->initializeQueue(); |
34 | 34 | } |
@@ -137,6 +137,6 @@ |
||
137 | 137 | return $index; |
138 | 138 | } |
139 | 139 | |
140 | - throw new MapContainerException('childPid not found. pid: ' . $childPid); |
|
140 | + throw new MapContainerException('childPid not found. pid: '.$childPid); |
|
141 | 141 | } |
142 | 142 | } |
@@ -2,7 +2,6 @@ |
||
2 | 2 | namespace Ackintosh\Snidel; |
3 | 3 | |
4 | 4 | use Ackintosh\Snidel\IpcKey; |
5 | -use Opis\Closure\SerializableClosure; |
|
6 | 5 | |
7 | 6 | class ResultQueue |
8 | 7 | { |
@@ -11,6 +11,9 @@ |
||
11 | 11 | private $queuedCount = 0; |
12 | 12 | private $dequeuedCount = 0; |
13 | 13 | |
14 | + /** |
|
15 | + * @param integer $ownerPid |
|
16 | + */ |
|
14 | 17 | public function __construct($ownerPid) |
15 | 18 | { |
16 | 19 | $this->ownerPid = $ownerPid; |
@@ -11,6 +11,9 @@ |
||
11 | 11 | private $queuedCount = 0; |
12 | 12 | private $dequeuedCount = 0; |
13 | 13 | |
14 | + /** |
|
15 | + * @param integer $ownerPid |
|
16 | + */ |
|
14 | 17 | public function __construct($ownerPid) |
15 | 18 | { |
16 | 19 | $this->ownerPid = $ownerPid; |
@@ -98,8 +98,8 @@ |
||
98 | 98 | */ |
99 | 99 | private function getCollectionWithTag($tag) |
100 | 100 | { |
101 | - $collection = array_filter($this->forks, function ($fork) use ($tag) { |
|
102 | - return $fork->getTag() === $tag; |
|
101 | + $collection = array_filter($this->forks, function($fork) use ($tag) { |
|
102 | + return $fork->getTag() === $tag; |
|
103 | 103 | }); |
104 | 104 | |
105 | 105 | return new ForkCollection($collection); |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @param callable $callable |
18 | 18 | * @param array $args |
19 | - * @param string $string |
|
19 | + * @param string|null $tag |
|
20 | 20 | */ |
21 | 21 | public function __construct($callable, $args, $tag) |
22 | 22 | { |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * @return string|null |
|
63 | + * @return string |
|
64 | 64 | */ |
65 | 65 | public function getTag() |
66 | 66 | { |
@@ -180,6 +180,7 @@ discard block |
||
180 | 180 | * fork worker process |
181 | 181 | * |
182 | 182 | * @param \Ackintosh\Snidel\Task |
183 | + * @param Task $task |
|
183 | 184 | * @return void |
184 | 185 | * @throws \RuntimeException |
185 | 186 | */ |
@@ -239,7 +240,7 @@ discard block |
||
239 | 240 | * @param mixed $args |
240 | 241 | * @param string $tag |
241 | 242 | * @param \Ackintosh\Snidel\Token $token |
242 | - * @return void |
|
243 | + * @return integer |
|
243 | 244 | * @throws \RuntimeException |
244 | 245 | */ |
245 | 246 | public function forkSimply($callable, $args = array(), $tag = null, Token $token = null) |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | foreach ($this->signals as $sig) { |
86 | 86 | $this->pcntl->signal( |
87 | 87 | $sig, |
88 | - function ($sig) use($log, $token, $self) { |
|
89 | - $log->info('received signal. signo: ' . $sig); |
|
88 | + function($sig) use($log, $token, $self) { |
|
89 | + $log->info('received signal. signo: '.$sig); |
|
90 | 90 | $self->setReceivedSignal($sig); |
91 | 91 | |
92 | 92 | $log->info('--> sending a signal to children.'); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - $this->log->info('parent pid: ' . $this->ownerPid); |
|
105 | + $this->log->info('parent pid: '.$this->ownerPid); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | throw $e; |
139 | 139 | } |
140 | 140 | |
141 | - $this->log->info('queued task #' . $this->forkContainer->queuedCount()); |
|
141 | + $this->log->info('queued task #'.$this->forkContainer->queuedCount()); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -154,20 +154,20 @@ discard block |
||
154 | 154 | |
155 | 155 | if ($pid) { |
156 | 156 | // owner |
157 | - $this->log->info('pid: ' . getmypid()); |
|
157 | + $this->log->info('pid: '.getmypid()); |
|
158 | 158 | } elseif ($pid === -1) { |
159 | 159 | // error |
160 | 160 | } else { |
161 | 161 | // master |
162 | 162 | $taskQueue = new TaskQueue($this->ownerPid); |
163 | - $this->log->info('pid: ' . $this->masterProcessId); |
|
163 | + $this->log->info('pid: '.$this->masterProcessId); |
|
164 | 164 | |
165 | 165 | foreach ($this->signals as $sig) { |
166 | 166 | $this->pcntl->signal($sig, SIG_DFL, true); |
167 | 167 | } |
168 | 168 | |
169 | 169 | while ($task = $taskQueue->dequeue()) { |
170 | - $this->log->info('dequeued task #' . $taskQueue->dequeuedCount()); |
|
170 | + $this->log->info('dequeued task #'.$taskQueue->dequeuedCount()); |
|
171 | 171 | if ($this->token->accept()) { |
172 | 172 | $this->forkWorker($task); |
173 | 173 | } |
@@ -196,10 +196,10 @@ discard block |
||
196 | 196 | |
197 | 197 | if (getmypid() === $this->masterProcessId) { |
198 | 198 | // master |
199 | - $this->log->info('forked worker. pid: ' . $fork->getPid()); |
|
199 | + $this->log->info('forked worker. pid: '.$fork->getPid()); |
|
200 | 200 | } else { |
201 | 201 | // worker |
202 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
202 | + $this->log->info('has forked. pid: '.getmypid()); |
|
203 | 203 | // @codeCoverageIgnoreStart |
204 | 204 | |
205 | 205 | foreach ($this->signals as $sig) { |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | } |
208 | 208 | |
209 | 209 | $resultQueue = new ResultQueue($this->ownerPid); |
210 | - register_shutdown_function(function () use ($fork, $resultQueue) { |
|
210 | + register_shutdown_function(function() use ($fork, $resultQueue) { |
|
211 | 211 | if ($fork->hasNoResult() || !$fork->isQueued()) { |
212 | 212 | $result = new Result(); |
213 | 213 | $result->setFailure(); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | |
259 | 259 | if (getmypid() === $this->ownerPid) { |
260 | 260 | // parent |
261 | - $this->log->info('created child process. pid: ' . $fork->getPid()); |
|
261 | + $this->log->info('created child process. pid: '.$fork->getPid()); |
|
262 | 262 | $this->childPids[] = $fork->getPid(); |
263 | 263 | } else { |
264 | 264 | // @codeCoverageIgnoreStart |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $dataRepository = $this->dataRepository; |
274 | 274 | $log = $this->log; |
275 | 275 | $processToken = $this->processToken; |
276 | - register_shutdown_function(function () use ($fork, $dataRepository, $log, $processToken) { |
|
276 | + register_shutdown_function(function() use ($fork, $dataRepository, $log, $processToken) { |
|
277 | 277 | $data = $dataRepository->load(getmypid()); |
278 | 278 | try { |
279 | 279 | $data->write($fork); |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | } |
321 | 321 | |
322 | 322 | if ($fork->hasNotFinishedSuccessfully()) { |
323 | - $message = 'an error has occurred in child process. pid: ' . $fork->getPid(); |
|
323 | + $message = 'an error has occurred in child process. pid: '.$fork->getPid(); |
|
324 | 324 | $this->log->error($message); |
325 | 325 | } |
326 | 326 | unset($this->childPids[array_search($fork->getPid(), $this->childPids)]); |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | } |
374 | 374 | |
375 | 375 | if (!$this->forkContainer->hasTag($tag)) { |
376 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
376 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | return $this->forkContainer->getCollection($tag); |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | } |
398 | 398 | |
399 | 399 | if (!$this->forkContainer->hasTag($tag)) { |
400 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
400 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | return $this->forkContainer->getCollection($tag); |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | public function sendSignalToChildren($sig) |
413 | 413 | { |
414 | 414 | foreach ($this->childPids as $pid) { |
415 | - $this->log->info('----> sending a signal to child. pid: ' . $pid); |
|
415 | + $this->log->info('----> sending a signal to child. pid: '.$pid); |
|
416 | 416 | posix_kill($pid, $sig); |
417 | 417 | } |
418 | 418 | } |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | |
515 | 515 | $childPid = $fork->getPid(); |
516 | 516 | if ($fork->hasNotFinishedSuccessfully()) { |
517 | - $message = 'an error has occurred in child process. pid: ' . $childPid; |
|
517 | + $message = 'an error has occurred in child process. pid: '.$childPid; |
|
518 | 518 | $this->log->error($message); |
519 | 519 | throw new \RuntimeException($message); |
520 | 520 | } |