Author: Nikolay Bondarenko (misterionkell@gmail.com)
Inheritance: implements Countable, use trait Ko\Mixin\ProcessTitle, use trait Ko\Mixin\EventEmitter
 public function testReSpawnedProcessHasPersistSharedMemorySegment()
 {
     $process = $this->manager->spawn(function (Process $p) {
         $sm = $p->getSharedMemory();
         $sm['spawnCount'] += 1;
         $exitCode = $sm['spawnCount'] == 1 ? -1 : 0;
         exit($exitCode);
     });
     $this->manager->wait();
     $this->assertEquals(2, $process->getSharedMemory()['spawnCount']);
 }
Beispiel #2
0
 protected function runChilds()
 {
     $count = $this->getWorkerCount();
     for ($i = 0; $i < $count; $i++) {
         $closure = $this->getChildCallable();
         if ($this->isForkMode()) {
             $this->processManager->fork($closure);
         } else {
             $this->processManager->spawn($closure);
         }
     }
 }
 /**
  * Dispatch a job to a worker.
  *
  * @param mixed $payload
  * @return void
  */
 public function dispatch($payload)
 {
     $this->manager->fork($this->getDispatchAction($payload));
 }
Beispiel #4
0
 public function testProcessCanTerminateOnSigTerm()
 {
     $m = new ProcessManager();
     $process = $m->fork(function (Process &$p) {
         while (!$p->isShouldShutdown()) {
             $p->dispatch();
             usleep(100);
         }
     });
     $process->kill();
     $process->wait();
     $this->assertFalse($m->hasAlive());
 }
Beispiel #5
0
 /**
  * Print process title
  *
  * @param OutputInterface $output
  * @param ForkProcess $p
  * @param ProcessManager $manager
  * @return null
  */
 private function createProcessTitle(OutputInterface $output, ForkProcess $p, $manager)
 {
     $processTitle = sprintf($this->prompt['START_PROCESS'], 'subscribers', $p->getPid());
     $manager->demonize();
     $p->setProcessTitle($processTitle);
     $this->logOutput($output, $processTitle, '<bg=white;options=bold>%s</>');
     return null;
 }