@@ -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 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function generate() |
| 28 | 28 | { |
| 29 | - $pathname = '/tmp/' . $this->prefix . $this->ownerPid; |
|
| 29 | + $pathname = '/tmp/'.$this->prefix.$this->ownerPid; |
|
| 30 | 30 | if (!file_exists($pathname)) { |
| 31 | 31 | touch($pathname); |
| 32 | 32 | } |
@@ -52,6 +52,6 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function delete() |
| 54 | 54 | { |
| 55 | - unlink('/tmp/' . $this->prefix . $this->ownerPid); |
|
| 55 | + unlink('/tmp/'.$this->prefix.$this->ownerPid); |
|
| 56 | 56 | } |
| 57 | 57 | } |
@@ -255,7 +255,7 @@ |
||
| 255 | 255 | * @param mixed $args |
| 256 | 256 | * @param string $tag |
| 257 | 257 | * @param \Ackintosh\Snidel\Token $token |
| 258 | - * @return void |
|
| 258 | + * @return integer |
|
| 259 | 259 | * @throws \RuntimeException |
| 260 | 260 | */ |
| 261 | 261 | public function forkSimply($callable, $args = array(), $tag = null, Token $token = null) |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | foreach ($this->signals as $sig) { |
| 95 | 95 | $this->pcntl->signal( |
| 96 | 96 | $sig, |
| 97 | - function ($sig) use($log, $token, $self) { |
|
| 98 | - $log->info('received signal. signo: ' . $sig); |
|
| 97 | + function($sig) use($log, $token, $self) { |
|
| 98 | + $log->info('received signal. signo: '.$sig); |
|
| 99 | 99 | $self->setReceivedSignal($sig); |
| 100 | 100 | |
| 101 | 101 | $log->info('--> sending a signal to children.'); |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | ); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - $this->log->info('parent pid: ' . $this->ownerPid); |
|
| 114 | + $this->log->info('parent pid: '.$this->ownerPid); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | throw $e; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $this->log->info('queued task #' . $this->taskQueue->queuedCount()); |
|
| 154 | + $this->log->info('queued task #'.$this->taskQueue->queuedCount()); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -167,17 +167,17 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | if ($pid) { |
| 169 | 169 | // owner |
| 170 | - $this->log->info('pid: ' . getmypid()); |
|
| 170 | + $this->log->info('pid: '.getmypid()); |
|
| 171 | 171 | } elseif ($pid === -1) { |
| 172 | 172 | // error |
| 173 | 173 | } else { |
| 174 | 174 | // master |
| 175 | - $this->log->info('pid: ' . $this->masterProcessId); |
|
| 175 | + $this->log->info('pid: '.$this->masterProcessId); |
|
| 176 | 176 | foreach ($this->signals as $sig) { |
| 177 | 177 | $this->pcntl->signal($sig, SIG_DFL, true); |
| 178 | 178 | } |
| 179 | 179 | while ($task = $this->taskQueue->dequeue()) { |
| 180 | - $this->log->info('dequeued task #' . $this->taskQueue->dequeuedCount()); |
|
| 180 | + $this->log->info('dequeued task #'.$this->taskQueue->dequeuedCount()); |
|
| 181 | 181 | if ($this->token->accept()) { |
| 182 | 182 | $this->forkWorker($task['callable'], $task['args'], $task['tag']); |
| 183 | 183 | } |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | if (getmypid() === $this->masterProcessId) { |
| 216 | 216 | // master |
| 217 | - $this->log->info('forked worker. pid: ' . $fork->getPid()); |
|
| 217 | + $this->log->info('forked worker. pid: '.$fork->getPid()); |
|
| 218 | 218 | } else { |
| 219 | 219 | // worker |
| 220 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
| 220 | + $this->log->info('has forked. pid: '.getmypid()); |
|
| 221 | 221 | // @codeCoverageIgnoreStart |
| 222 | 222 | foreach ($this->signals as $sig) { |
| 223 | 223 | $this->pcntl->signal($sig, SIG_DFL, true); |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $resultHasQueued = false; |
| 227 | 227 | // in php5.3, $this is not usable directly with closures. |
| 228 | 228 | $resultQueue = $this->resultQueue; |
| 229 | - register_shutdown_function(function () use ($fork, $resultQueue, &$resultHasQueued) { |
|
| 229 | + register_shutdown_function(function() use ($fork, $resultQueue, &$resultHasQueued) { |
|
| 230 | 230 | if ($fork->hasNoResult() || $resultHasQueued === false) { |
| 231 | 231 | $result = new Result(); |
| 232 | 232 | $result->setFailure(); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | |
| 283 | 283 | if (getmypid() === $this->ownerPid) { |
| 284 | 284 | // parent |
| 285 | - $this->log->info('created child process. pid: ' . $fork->getPid()); |
|
| 285 | + $this->log->info('created child process. pid: '.$fork->getPid()); |
|
| 286 | 286 | $this->childPids[] = $fork->getPid(); |
| 287 | 287 | } else { |
| 288 | 288 | // @codeCoverageIgnoreStart |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $dataRepository = $this->dataRepository; |
| 299 | 299 | $log = $this->log; |
| 300 | 300 | $processToken = $this->processToken; |
| 301 | - register_shutdown_function(function () use ($result, $dataRepository, $log, $processToken) { |
|
| 301 | + register_shutdown_function(function() use ($result, $dataRepository, $log, $processToken) { |
|
| 302 | 302 | $data = $dataRepository->load(getmypid()); |
| 303 | 303 | try { |
| 304 | 304 | $data->write($result); |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | $childPid = $fork->getPid(); |
| 350 | 350 | $result = $fork->getResult(); |
| 351 | 351 | if ($fork->hasNotFinishedSuccessfully()) { |
| 352 | - $message = 'an error has occurred in child process. pid: ' . $childPid; |
|
| 352 | + $message = 'an error has occurred in child process. pid: '.$childPid; |
|
| 353 | 353 | $this->log->error($message); |
| 354 | 354 | $this->error[$childPid] = array( |
| 355 | 355 | 'status' => $fork->getStatus(), |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | if (!$this->forkContainer->hasTag($tag)) { |
| 419 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
| 419 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | return $this->forkContainer->getCollection($tag); |
@@ -443,12 +443,12 @@ discard block |
||
| 443 | 443 | return new ForkCollection($this->forks); |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | - $filtered = array_filter($this->forks, function ($fork) use ($tag) { |
|
| 446 | + $filtered = array_filter($this->forks, function($fork) use ($tag) { |
|
| 447 | 447 | return $fork->getTag() === $tag; |
| 448 | 448 | }); |
| 449 | 449 | |
| 450 | 450 | if (count($filtered) === 0) { |
| 451 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
| 451 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | return new ForkCollection($filtered); |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | public function sendSignalToChildren($sig) |
| 464 | 464 | { |
| 465 | 465 | foreach ($this->childPids as $pid) { |
| 466 | - $this->log->info('----> sending a signal to child. pid: ' . $pid); |
|
| 466 | + $this->log->info('----> sending a signal to child. pid: '.$pid); |
|
| 467 | 467 | posix_kill($pid, $sig); |
| 468 | 468 | } |
| 469 | 469 | } |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | |
| 566 | 566 | $childPid = $fork->getPid(); |
| 567 | 567 | if ($fork->hasNotFinishedSuccessfully()) { |
| 568 | - $message = 'an error has occurred in child process. pid: ' . $childPid; |
|
| 568 | + $message = 'an error has occurred in child process. pid: '.$childPid; |
|
| 569 | 569 | $this->log->error($message); |
| 570 | 570 | throw new \RuntimeException($message); |
| 571 | 571 | } |
@@ -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 | { |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | public function __construct($ownerPid) |
| 15 | 15 | { |
| 16 | 16 | $this->ownerPid = $ownerPid; |
| 17 | - $this->ipcKey = new IpcKey($ownerPid, 'snidel_result_' . uniqid((string) mt_rand(1, 100), true)); |
|
| 17 | + $this->ipcKey = new IpcKey($ownerPid, 'snidel_result_'.uniqid((string) mt_rand(1, 100), true)); |
|
| 18 | 18 | $this->id = msg_get_queue($this->ipcKey->generate()); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -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; |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | public function __construct($ownerPid) |
| 15 | 15 | { |
| 16 | 16 | $this->ownerPid = $ownerPid; |
| 17 | - $this->ipcKey = new IpcKey($ownerPid, 'snidel_task_' . uniqid((string) mt_rand(1, 100), true)); |
|
| 17 | + $this->ipcKey = new IpcKey($ownerPid, 'snidel_task_'.uniqid((string) mt_rand(1, 100), true)); |
|
| 18 | 18 | $this->id = msg_get_queue($this->ipcKey->generate()); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -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); |