/** * @test */ public function error() { $fp = fopen('php://temp', 'w'); $this->log->setdestination($fp); $this->log->error('test'); rewind($fp); $this->assertStringMatchesFormat('%s[error]%s', fgets($fp)); }
public function __destruct() { if ($this->ownerPid === getmypid()) { if ($this->container->existsMaster()) { $this->log->info('shutdown master process.'); $this->container->sendSignalToMaster(); } unset($this->container); } if ($this->exceptionHasOccured) { $this->log->info('destruct processes are started.(exception has occured)'); $this->log->info('--> deleting all shared memory.'); $this->deleteAllData(); } elseif ($this->ownerPid === getmypid() && !$this->joined && $this->receivedSignal === null) { $message = 'snidel will have to wait for the child process is completed. please use Snidel::wait()'; $this->log->error($message); throw new \LogicException($message); } }
/** * fork worker process * * @param \Ackintosh\Snidel\Task * @return \Ackintosh\Snidel\Worker * @throws \RuntimeException */ private function forkWorker($task) { try { $fork = $this->fork(); } catch (\RuntimeException $e) { $this->log->error($e->getMessage()); throw $e; } $worker = new Worker($fork, $task); if (getmypid() === $this->masterPid) { // master $this->log->info('forked worker. pid: ' . $worker->getPid()); return $worker; } else { // worker // @codeCoverageIgnoreStart $this->log->info('has forked. pid: ' . getmypid()); foreach ($this->signals as $sig) { $this->pcntl->signal($sig, SIG_DFL, true); } $worker->setResultQueue($this->queueFactory->createResultQueue()); $resultHasQueued = false; register_shutdown_function(function () use(&$resultHasQueued, $worker) { if (!$resultHasQueued) { $worker->error(); } }); $this->log->info('----> started the function.'); try { $worker->run(); } catch (\RuntimeException $e) { $this->log->error($e->getMessage()); exit; } $this->log->info('<---- completed the function.'); $resultHasQueued = true; $this->log->info('queued the result and exit.'); exit; // @codeCoverageIgnoreEnd } }