/** * Recovers instance from plain data. * * @param array $data Data of object to restore. * @param Daemon $instance Optionaly, target instance which should be recovered. * @return Daemon Recovered instance. * @throws InvalidArgumentException When argument of invalid type is passed. * @version 0.0.1 * @since 0.0.1 */ public static function fromArray(array $data, \Pork\SerializationHandler $instance = null) { if (isset($instance) && !$instance instanceof self) { throw new InvalidArgumentException(\sprintf('Pork\\Process\\Daemon::fromArray() can work only on Pork\\Process\\Daemon instances - %s given.', \get_class($instance))); } // core data $instance = parent::fromArray($data, $instance); // additional daemon info $instance->outputLog = $data['outputLog']; $instance->errorLog = $data['errorLog']; $instance->uid = $data['uid']; $instance->gid = $data['gid']; return $instance; }
/** * Checks if process is running. * * @return bool Process running state. * @version 0.0.1 * @since 0.0.1 */ public function isRunning() { // no PID - nothing more to do if (!\file_exists($this->pidFile)) { return false; } $pid = \file_get_contents($this->pidFile); if (\is_numeric($pid)) { if (\Pork\Process::checkRunning($pid)) { // remember it here, why bother in future? $this->pid = $pid; // unfortunately we can't check if it's our process return true; } } // not running - delete orphaned PID file $this->clear(); return false; }