Author: Nikolay Bondarenko (misterionkell@gmail.com)
Inheritance: implements Countable, use trait Ko\Mixin\ProcessTitle, use trait Ko\Mixin\EventEmitter
コード例 #1
0
 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']);
 }
コード例 #2
0
ファイル: Application.php プロジェクト: umpirsky/ko-worker
 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);
         }
     }
 }
コード例 #3
0
 /**
  * Dispatch a job to a worker.
  *
  * @param mixed $payload
  * @return void
  */
 public function dispatch($payload)
 {
     $this->manager->fork($this->getDispatchAction($payload));
 }
コード例 #4
0
ファイル: ProcessTest.php プロジェクト: meckhardt/ko-process
 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());
 }
コード例 #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;
 }