Cronario\Producer::stop PHP Méthode

stop() public méthode

public stop ( boolean $async = false ) : boolean
$async boolean
Résultat boolean
    public function stop($async = false)
    {
        $state = $this->getState();
        if (in_array($state, [self::STATE_T_START, self::STATE_T_STOP, self::STATE_T_KILL]) && !$this->processExists()) {
            $this->getLogger()->warning("Daemon is ill cant find process {$this->getProcessId()}, try clean data", [__NAMESPACE__]);
            $this->cleanData();
            return true;
        }
        if (in_array($state, [self::STATE_T_STOP, self::STATE_T_KILL])) {
            $this->getLogger()->info("Daemon can't STOP, cause state : {$state}", [__NAMESPACE__]);
            return true;
        }
        if (!in_array($state, [self::STATE_T_START])) {
            $this->getLogger()->info("Daemon can't STOP, cause daemon not START", [__NAMESPACE__]);
            return true;
        }
        $this->setState(self::STATE_T_STOP);
        // sync mode (wait for stopping loop)
        if ($async) {
            return true;
        }
        $this->getLogger()->info("Daemon sync STOP, wait loop ...", [__NAMESPACE__]);
        $sleep = $this->getConfig(self::CONFIG_SLEEP_STOP_LOOP);
        while ($this->isState([self::STATE_T_STOP, self::STATE_T_KILL, self::STATE_T_START])) {
            $this->getLogger()->debug("Daemon sync STOP, wait loop .......", [__NAMESPACE__]);
            sleep($sleep);
        }
        return true;
    }