@@ -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) |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | foreach ($this->signals as $sig) { |
| 96 | 96 | $this->pcntl->signal( |
| 97 | 97 | $sig, |
| 98 | - function ($sig) use($log, $token, $self) { |
|
| 99 | - $log->info('received signal. signo: ' . $sig); |
|
| 98 | + function($sig) use($log, $token, $self) { |
|
| 99 | + $log->info('received signal. signo: '.$sig); |
|
| 100 | 100 | $self->setReceivedSignal($sig); |
| 101 | 101 | |
| 102 | 102 | $log->info('--> sending a signal to children.'); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | ); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $this->log->info('parent pid: ' . $this->ownerPid); |
|
| 115 | + $this->log->info('parent pid: '.$this->ownerPid); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | throw $e; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - $this->log->info('queued task #' . $this->taskQueue->queuedCount()); |
|
| 151 | + $this->log->info('queued task #'.$this->taskQueue->queuedCount()); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -164,17 +164,17 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | if ($pid) { |
| 166 | 166 | // owner |
| 167 | - $this->log->info('pid: ' . getmypid()); |
|
| 167 | + $this->log->info('pid: '.getmypid()); |
|
| 168 | 168 | } elseif ($pid === -1) { |
| 169 | 169 | // error |
| 170 | 170 | } else { |
| 171 | 171 | // master |
| 172 | - $this->log->info('pid: ' . $this->masterProcessId); |
|
| 172 | + $this->log->info('pid: '.$this->masterProcessId); |
|
| 173 | 173 | foreach ($this->signals as $sig) { |
| 174 | 174 | $this->pcntl->signal($sig, SIG_DFL, true); |
| 175 | 175 | } |
| 176 | 176 | while ($task = $this->taskQueue->dequeue()) { |
| 177 | - $this->log->info('dequeued task #' . $this->taskQueue->dequeuedCount()); |
|
| 177 | + $this->log->info('dequeued task #'.$this->taskQueue->dequeuedCount()); |
|
| 178 | 178 | if ($this->token->accept()) { |
| 179 | 179 | $this->forkWorker($task); |
| 180 | 180 | } |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | if (getmypid() === $this->masterProcessId) { |
| 205 | 205 | // master |
| 206 | - $this->log->info('forked worker. pid: ' . $fork->getPid()); |
|
| 206 | + $this->log->info('forked worker. pid: '.$fork->getPid()); |
|
| 207 | 207 | } else { |
| 208 | 208 | // worker |
| 209 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
| 209 | + $this->log->info('has forked. pid: '.getmypid()); |
|
| 210 | 210 | // @codeCoverageIgnoreStart |
| 211 | 211 | foreach ($this->signals as $sig) { |
| 212 | 212 | $this->pcntl->signal($sig, SIG_DFL, true); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | // in php5.3, $this is not usable directly with closures. |
| 216 | 216 | $resultQueue = $this->resultQueue; |
| 217 | - register_shutdown_function(function () use ($fork, $resultQueue) { |
|
| 217 | + register_shutdown_function(function() use ($fork, $resultQueue) { |
|
| 218 | 218 | if ($fork->hasNoResult() || !$fork->isQueued()) { |
| 219 | 219 | $result = new Result(); |
| 220 | 220 | $result->setFailure(); |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | if (getmypid() === $this->ownerPid) { |
| 266 | 266 | // parent |
| 267 | - $this->log->info('created child process. pid: ' . $fork->getPid()); |
|
| 267 | + $this->log->info('created child process. pid: '.$fork->getPid()); |
|
| 268 | 268 | $this->childPids[] = $fork->getPid(); |
| 269 | 269 | } else { |
| 270 | 270 | // @codeCoverageIgnoreStart |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | $dataRepository = $this->dataRepository; |
| 280 | 280 | $log = $this->log; |
| 281 | 281 | $processToken = $this->processToken; |
| 282 | - register_shutdown_function(function () use ($fork, $dataRepository, $log, $processToken) { |
|
| 282 | + register_shutdown_function(function() use ($fork, $dataRepository, $log, $processToken) { |
|
| 283 | 283 | $data = $dataRepository->load(getmypid()); |
| 284 | 284 | try { |
| 285 | 285 | $data->write($fork->getResult()); |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | $childPid = $fork->getPid(); |
| 329 | 329 | $result = $fork->getResult(); |
| 330 | 330 | if ($fork->hasNotFinishedSuccessfully()) { |
| 331 | - $message = 'an error has occurred in child process. pid: ' . $childPid; |
|
| 331 | + $message = 'an error has occurred in child process. pid: '.$childPid; |
|
| 332 | 332 | $this->log->error($message); |
| 333 | 333 | $this->error[$childPid] = array( |
| 334 | 334 | 'status' => $fork->getStatus(), |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | if (!$this->forkContainer->hasTag($tag)) { |
| 398 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
| 398 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | return $this->forkContainer->getCollection($tag); |
@@ -422,12 +422,12 @@ discard block |
||
| 422 | 422 | return new ForkCollection($this->forks); |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - $filtered = array_filter($this->forks, function ($fork) use ($tag) { |
|
| 425 | + $filtered = array_filter($this->forks, function($fork) use ($tag) { |
|
| 426 | 426 | return $fork->getTag() === $tag; |
| 427 | 427 | }); |
| 428 | 428 | |
| 429 | 429 | if (count($filtered) === 0) { |
| 430 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
| 430 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | return new ForkCollection($filtered); |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | public function sendSignalToChildren($sig) |
| 443 | 443 | { |
| 444 | 444 | foreach ($this->childPids as $pid) { |
| 445 | - $this->log->info('----> sending a signal to child. pid: ' . $pid); |
|
| 445 | + $this->log->info('----> sending a signal to child. pid: '.$pid); |
|
| 446 | 446 | posix_kill($pid, $sig); |
| 447 | 447 | } |
| 448 | 448 | } |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | $childPid = $fork->getPid(); |
| 546 | 546 | if ($fork->hasNotFinishedSuccessfully()) { |
| 547 | - $message = 'an error has occurred in child process. pid: ' . $childPid; |
|
| 547 | + $message = 'an error has occurred in child process. pid: '.$childPid; |
|
| 548 | 548 | $this->log->error($message); |
| 549 | 549 | throw new \RuntimeException($message); |
| 550 | 550 | } |
@@ -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); |