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); } } }
public function testShutdownHandlerWasCalledOnSigTerm() { $process = $this->manager->fork(function (Process $p) { $sm = $p->getSharedMemory(); $m = new ProcessManager(); $m->onShutdown(function () use(&$sm) { $sm['wasCalled'] = true; })->fork(function () { usleep(300000); }); $sm['ready'] = true; $m->wait(); }); $this->waitReady($process); $process->kill(); $this->manager->wait(); $sm = $process->getSharedMemory(); $this->assertTrue($sm['wasCalled']); }
/** * Dispatch a job to a worker. * * @param mixed $payload * @return void */ public function dispatch($payload) { $this->manager->fork($this->getDispatchAction($payload)); }
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()); }
/** * Verify subscribers email addresses * * @param OutputInterface $output * @param \Deliveries\Service\AppServiceManager $serviceManager * @param array $request */ private function subscribersVerify(OutputInterface $output, AppServiceManager $serviceManager, array $request) { // get subscribers $subscribers = $serviceManager->getUncheckedSubscribers($request['subscribers']); // count number of processes forks $forks = count($subscribers); $manager = new ProcessManager(); // start process forks for ($f = 0; $f < $forks; $f++) { $manager->fork(function (ForkProcess $p) use($subscribers, $output, $f, $serviceManager, $manager) { // create process title $this->createProcessTitle($output, $p, $manager); // create progress instance with total of subscribers $progress = $this->createProgress($output, $count = count($subscribers[$f])); while (++$this->i < $count) { // verify subscriber email via SMTP $subscriber = $serviceManager->verifyEmail($subscribers[$f][$this->i]['email'], true, true); $subscriber->isValid() === true ? ++$this->valid : ++$this->invalid; // update subscriber verify state $serviceManager->setSubscriberState($subscribers[$f][$this->i]['subscriber_id'], $subscriber->isValid()); // print checkout process $this->printProcess($progress); if ($this->i >= $count) { $progress->finish(); break; } } })->onSuccess(function () use($output) { // process done $this->logOutput($output, $this->prompt['DONE_PROCESS'], ' <bg=white;options=bold>%s</>'); })->onError(function (ForkProcess $p) { throw new AppException('Error process: ' . $p->getPid()); })->wait(); } }