@@ -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) |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | foreach ($this->signals as $sig) { |
82 | 82 | $this->pcntl->signal( |
83 | 83 | $sig, |
84 | - function ($sig) use($log, $token, $self) { |
|
85 | - $log->info('received signal. signo: ' . $sig); |
|
84 | + function($sig) use($log, $token, $self) { |
|
85 | + $log->info('received signal. signo: '.$sig); |
|
86 | 86 | $self->setReceivedSignal($sig); |
87 | 87 | |
88 | 88 | $log->info('--> sending a signal to children.'); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | ); |
99 | 99 | } |
100 | 100 | |
101 | - $this->log->info('parent pid: ' . $this->ownerPid); |
|
101 | + $this->log->info('parent pid: '.$this->ownerPid); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | throw $e; |
135 | 135 | } |
136 | 136 | |
137 | - $this->log->info('queued task #' . $this->forkContainer->queuedCount()); |
|
137 | + $this->log->info('queued task #'.$this->forkContainer->queuedCount()); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -150,20 +150,20 @@ discard block |
||
150 | 150 | |
151 | 151 | if ($pid) { |
152 | 152 | // owner |
153 | - $this->log->info('pid: ' . getmypid()); |
|
153 | + $this->log->info('pid: '.getmypid()); |
|
154 | 154 | } elseif ($pid === -1) { |
155 | 155 | // error |
156 | 156 | } else { |
157 | 157 | // master |
158 | 158 | $taskQueue = new TaskQueue($this->ownerPid); |
159 | - $this->log->info('pid: ' . $this->masterProcessId); |
|
159 | + $this->log->info('pid: '.$this->masterProcessId); |
|
160 | 160 | |
161 | 161 | foreach ($this->signals as $sig) { |
162 | 162 | $this->pcntl->signal($sig, SIG_DFL, true); |
163 | 163 | } |
164 | 164 | |
165 | 165 | while ($task = $taskQueue->dequeue()) { |
166 | - $this->log->info('dequeued task #' . $taskQueue->dequeuedCount()); |
|
166 | + $this->log->info('dequeued task #'.$taskQueue->dequeuedCount()); |
|
167 | 167 | if ($this->token->accept()) { |
168 | 168 | $this->forkWorker($task); |
169 | 169 | } |
@@ -192,10 +192,10 @@ discard block |
||
192 | 192 | |
193 | 193 | if (getmypid() === $this->masterProcessId) { |
194 | 194 | // master |
195 | - $this->log->info('forked worker. pid: ' . $fork->getPid()); |
|
195 | + $this->log->info('forked worker. pid: '.$fork->getPid()); |
|
196 | 196 | } else { |
197 | 197 | // worker |
198 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
198 | + $this->log->info('has forked. pid: '.getmypid()); |
|
199 | 199 | // @codeCoverageIgnoreStart |
200 | 200 | |
201 | 201 | foreach ($this->signals as $sig) { |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | } |
204 | 204 | |
205 | 205 | $resultQueue = new ResultQueue($this->ownerPid); |
206 | - register_shutdown_function(function () use ($fork, $resultQueue) { |
|
206 | + register_shutdown_function(function() use ($fork, $resultQueue) { |
|
207 | 207 | if ($fork->hasNoResult() || !$fork->isQueued()) { |
208 | 208 | $result = new Result(); |
209 | 209 | $result->setFailure(); |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | |
255 | 255 | if (getmypid() === $this->ownerPid) { |
256 | 256 | // parent |
257 | - $this->log->info('created child process. pid: ' . $fork->getPid()); |
|
257 | + $this->log->info('created child process. pid: '.$fork->getPid()); |
|
258 | 258 | $this->childPids[] = $fork->getPid(); |
259 | 259 | } else { |
260 | 260 | // @codeCoverageIgnoreStart |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | $dataRepository = $this->dataRepository; |
270 | 270 | $log = $this->log; |
271 | 271 | $processToken = $this->processToken; |
272 | - register_shutdown_function(function () use ($fork, $dataRepository, $log, $processToken) { |
|
272 | + register_shutdown_function(function() use ($fork, $dataRepository, $log, $processToken) { |
|
273 | 273 | $data = $dataRepository->load(getmypid()); |
274 | 274 | try { |
275 | 275 | $data->write($fork); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | } |
317 | 317 | |
318 | 318 | if ($fork->hasNotFinishedSuccessfully()) { |
319 | - $message = 'an error has occurred in child process. pid: ' . $fork->getPid(); |
|
319 | + $message = 'an error has occurred in child process. pid: '.$fork->getPid(); |
|
320 | 320 | $this->log->error($message); |
321 | 321 | } |
322 | 322 | unset($this->childPids[array_search($fork->getPid(), $this->childPids)]); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | } |
366 | 366 | |
367 | 367 | if (!$this->forkContainer->hasTag($tag)) { |
368 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
368 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | return $this->forkContainer->getCollection($tag); |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | public function sendSignalToChildren($sig) |
381 | 381 | { |
382 | 382 | foreach ($this->childPids as $pid) { |
383 | - $this->log->info('----> sending a signal to child. pid: ' . $pid); |
|
383 | + $this->log->info('----> sending a signal to child. pid: '.$pid); |
|
384 | 384 | posix_kill($pid, $sig); |
385 | 385 | } |
386 | 386 | } |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | |
483 | 483 | $childPid = $fork->getPid(); |
484 | 484 | if ($fork->hasNotFinishedSuccessfully()) { |
485 | - $message = 'an error has occurred in child process. pid: ' . $childPid; |
|
485 | + $message = 'an error has occurred in child process. pid: '.$childPid; |
|
486 | 486 | $this->log->error($message); |
487 | 487 | throw new \RuntimeException($message); |
488 | 488 | } |