| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | $this->params['id'] = spl_object_hash($this); | 
| 24 | 24 |          if (!$this->params['driver']) { | 
| 25 | 25 | $this->params['driver'] = new FlatFileDriver( | 
| 26 | - sys_get_temp_dir() . DIRECTORY_SEPARATOR . $this->params['id'] | |
| 26 | + sys_get_temp_dir().DIRECTORY_SEPARATOR.$this->params['id'] | |
| 27 | 27 | ); | 
| 28 | 28 | } | 
| 29 | 29 | } | 
| @@ -105,7 +105,7 @@ discard block | ||
| 105 | 105 |          try { | 
| 106 | 106 | $this->master = $this->pcntl->fork(); | 
| 107 | 107 |          } catch (\RuntimeException $e) { | 
| 108 | - $message = 'failed to fork master: ' . $e->getMessage(); | |
| 108 | + $message = 'failed to fork master: '.$e->getMessage(); | |
| 109 | 109 | $this->log->error($message); | 
| 110 | 110 | throw new \RuntimeException($message); | 
| 111 | 111 | } | 
| @@ -114,8 +114,8 @@ discard block | ||
| 114 | 114 | |
| 115 | 115 |          if (getmypid() === $this->config->get('ownerPid')) { | 
| 116 | 116 | // owner | 
| 117 | -            $this->log->info('pid: ' . getmypid()); | |
| 118 | -            $this->resultQueue  = $this->factory->create('result'); | |
| 117 | +            $this->log->info('pid: '.getmypid()); | |
| 118 | +            $this->resultQueue = $this->factory->create('result'); | |
| 119 | 119 | |
| 120 | 120 | return $this->master; | 
| 121 | 121 |          } else { | 
| @@ -123,17 +123,17 @@ discard block | ||
| 123 | 123 | // covered by SnidelTest via master process | 
| 124 | 124 | // master | 
| 125 | 125 | $workerPool = new WorkerPool(); | 
| 126 | -            $this->log->info('pid: ' . $this->master->getPid()); | |
| 126 | +            $this->log->info('pid: '.$this->master->getPid()); | |
| 127 | 127 | |
| 128 | 128 |              foreach ($this->signals as $sig) { | 
| 129 | -                $this->pcntl->signal($sig, function ($sig) use ($workerPool) { | |
| 129 | +                $this->pcntl->signal($sig, function($sig) use ($workerPool) { | |
| 130 | 130 | $this->receivedSignal = $sig; | 
| 131 | -                    $this->log->info('received signal: ' . $sig); | |
| 131 | +                    $this->log->info('received signal: '.$sig); | |
| 132 | 132 | |
| 133 | 133 |                      if ($workerPool->count() === 0) { | 
| 134 | 134 |                          $this->log->info('no worker is active.'); | 
| 135 | 135 |                      } else { | 
| 136 | -                        $this->log->info('------> sending signal to workers. signal: ' . $sig); | |
| 136 | +                        $this->log->info('------> sending signal to workers. signal: '.$sig); | |
| 137 | 137 | $workerPool->terminate($sig); | 
| 138 | 138 |                          $this->log->info('<------ sent signal'); | 
| 139 | 139 | } | 
| @@ -141,7 +141,7 @@ discard block | ||
| 141 | 141 | }); | 
| 142 | 142 | } | 
| 143 | 143 | |
| 144 | -            $concurrency = (int)$this->config->get('concurrency'); | |
| 144 | +            $concurrency = (int) $this->config->get('concurrency'); | |
| 145 | 145 |              for ($i = 0; $i < $concurrency; $i++) { | 
| 146 | 146 | $workerPool->add($this->forkWorker()); | 
| 147 | 147 | } | 
| @@ -170,7 +170,7 @@ discard block | ||
| 170 | 170 |          try { | 
| 171 | 171 | $process = $this->pcntl->fork(); | 
| 172 | 172 |          } catch (\RuntimeException $e) { | 
| 173 | - $message = 'failed to fork worker: ' . $e->getMessage(); | |
| 173 | + $message = 'failed to fork worker: '.$e->getMessage(); | |
| 174 | 174 | $this->log->error($message); | 
| 175 | 175 | throw new \RuntimeException($message); | 
| 176 | 176 | } | 
| @@ -179,22 +179,22 @@ discard block | ||
| 179 | 179 | |
| 180 | 180 |          if (getmypid() === $this->master->getPid()) { | 
| 181 | 181 | // master | 
| 182 | -            $this->log->info('forked worker. pid: ' . $worker->getPid()); | |
| 182 | +            $this->log->info('forked worker. pid: '.$worker->getPid()); | |
| 183 | 183 | return $worker; | 
| 184 | 184 |          } else { | 
| 185 | 185 | // @codeCoverageIgnoreStart | 
| 186 | 186 | // covered by SnidelTest via worker process | 
| 187 | 187 | // worker | 
| 188 | -            $this->log->info('has forked. pid: ' . getmypid()); | |
| 188 | +            $this->log->info('has forked. pid: '.getmypid()); | |
| 189 | 189 | |
| 190 | 190 |              foreach ($this->signals as $sig) { | 
| 191 | -                $this->pcntl->signal($sig, function ($sig) { | |
| 191 | +                $this->pcntl->signal($sig, function($sig) { | |
| 192 | 192 | $this->receivedSignal = $sig; | 
| 193 | 193 | exit; | 
| 194 | 194 | }, false); | 
| 195 | 195 | } | 
| 196 | 196 | |
| 197 | -            register_shutdown_function(function () use ($worker) { | |
| 197 | +            register_shutdown_function(function() use ($worker) { | |
| 198 | 198 |                  if ($this->receivedSignal === null && $worker->isInProgress()) { | 
| 199 | 199 | $worker->error(); | 
| 200 | 200 | } | 
| @@ -225,14 +225,14 @@ discard block | ||
| 225 | 225 | */ | 
| 226 | 226 | public function sendSignalToMaster($sig = SIGTERM): void | 
| 227 | 227 |      { | 
| 228 | -        $this->log->info('----> sending signal to master. signal: ' . $sig); | |
| 228 | +        $this->log->info('----> sending signal to master. signal: '.$sig); | |
| 229 | 229 | posix_kill($this->master->getPid(), $sig); | 
| 230 | 230 |          $this->log->info('<---- sent signal.'); | 
| 231 | 231 | |
| 232 | 232 |          $this->log->info('----> waiting for master shutdown.'); | 
| 233 | 233 | $status = null; | 
| 234 | 234 | $this->pcntl->waitpid($this->master->getPid(), $status); | 
| 235 | -        $this->log->info('<---- master shutdown. status: ' . $status); | |
| 235 | +        $this->log->info('<---- master shutdown. status: '.$status); | |
| 236 | 236 | $this->master = null; | 
| 237 | 237 | } | 
| 238 | 238 | |
| @@ -38,7 +38,7 @@ | ||
| 38 | 38 | */ | 
| 39 | 39 | private function context(): array | 
| 40 | 40 |      { | 
| 41 | - $pid = getmypid(); | |
| 41 | + $pid = getmypid(); | |
| 42 | 42 |          switch ($pid) { | 
| 43 | 43 | case $this->ownerPid: | 
| 44 | 44 | $role = 'owner'; | 
| @@ -39,7 +39,7 @@ discard block | ||
| 39 | 39 | $this->coordinator = new Coordinator($this->config, $this->log); | 
| 40 | 40 | $this->coordinator->forkMaster(); | 
| 41 | 41 | $this->registerSignalHandler($this->coordinator, $this->log); | 
| 42 | -        $this->log->info('parent pid: ' . $this->config->get('ownerPid')); | |
| 42 | +        $this->log->info('parent pid: '.$this->config->get('ownerPid')); | |
| 43 | 43 | } | 
| 44 | 44 | |
| 45 | 45 | /** | 
| @@ -52,11 +52,11 @@ discard block | ||
| 52 | 52 |          try { | 
| 53 | 53 | $this->coordinator->enqueue(new Task($callable, $args, $tag)); | 
| 54 | 54 |          } catch (\RuntimeException $e) { | 
| 55 | -            $this->log->error('failed to enqueue the task: ' . $e->getMessage()); | |
| 55 | +            $this->log->error('failed to enqueue the task: '.$e->getMessage()); | |
| 56 | 56 | throw $e; | 
| 57 | 57 | } | 
| 58 | 58 | |
| 59 | -        $this->log->info('queued task #' . $this->coordinator->queuedCount()); | |
| 59 | +        $this->log->info('queued task #'.$this->coordinator->queuedCount()); | |
| 60 | 60 | } | 
| 61 | 61 | |
| 62 | 62 | /** | 
| @@ -72,7 +72,7 @@ discard block | ||
| 72 | 72 | */ | 
| 73 | 73 | public function results(): \Generator | 
| 74 | 74 |      { | 
| 75 | -        foreach($this->coordinator->results() as $r) { | |
| 75 | +        foreach ($this->coordinator->results() as $r) { | |
| 76 | 76 | yield $r; | 
| 77 | 77 | } | 
| 78 | 78 | } | 
| @@ -97,8 +97,8 @@ discard block | ||
| 97 | 97 |          foreach ($this->signals as $sig) { | 
| 98 | 98 | $pcntl->signal( | 
| 99 | 99 | $sig, | 
| 100 | -                function ($sig) use ($log, $coordinator) { | |
| 101 | -                    $log->info('received signal. signo: ' . $sig); | |
| 100 | +                function($sig) use ($log, $coordinator) { | |
| 101 | +                    $log->info('received signal. signo: '.$sig); | |
| 102 | 102 |                      $log->info('--> sending a signal " to children.'); | 
| 103 | 103 | $coordinator->sendSignalToMaster($sig); | 
| 104 | 104 |                      $log->info('<-- signal handling has been completed successfully.'); |