[李景山php]每天TP5-20170123|thinkphp5-Process.php-5

    /**
     * 開啓從底層過程獲取輸出和錯誤輸出。
     * @return Process
     * @throws \RuntimeException
     */
    public function enableOutput()
    {// enableOutput
        if ($this->isRunning()) {// 如果 運行
            throw new \RuntimeException('Enabling output while the process is running is not possible.');
        }

        $this->outputDisabled = false;// 輸出 標誌位 禁止

        return $this;// 返回 類本身
    }

    /**
     * 輸出是否禁用
     * @return bool
     */
    public function isOutputDisabled()// 返回 是否 isOutputDisabled 直接返回 當前結果
    {
        return $this->outputDisabled;
    }

    /**
     * 獲取當前的輸出管道
     * @return string
     * @throws \LogicException
     * @throws \LogicException
     * @api
     */
    public function getOutput()// 獲取 當前的 輸出 管道
    {
        if ($this->outputDisabled) {// 如果 禁止 輸出
            throw new \LogicException('Output has been disabled.');// logicException
        }

        $this->requireProcessIsStarted(__FUNCTION__);// 獲取進程 開始

        $this->readPipes(false, '\\' === DS ? !$this->processInformation['running'] : true);// 讀取管道信息

        return $this->stdout;// 返回輸出 信息
        // processInformation
    }

    /**
     * 以增量方式返回的輸出結果。
     * @return string
     */
    public function getIncrementalOutput()
    {// 以增量方式返回的輸出結果
        $this->requireProcessIsStarted(__FUNCTION__);// 開始進程

        $data = $this->getOutput();// 獲取輸出信息

        $latest = substr($data, $this->incrementalOutputOffset);// 增量位置

        if (false === $latest) {// 如果增量 爲空
            return '';
        }

        $this->incrementalOutputOffset = strlen($data);// 標註下一次的 起始位置

        return $latest;// 返回 增量 是個字符串
    }

    /**
     * 清空輸出
     * @return Process
     */
    public function clearOutput()// 清空 輸出
    {
        $this->stdout                  = '';// 總的輸出 數據
        $this->incrementalOutputOffset = 0;// 增量位置 初始化爲0

        return $this;// 返回 類本身
    }

    /**
     * 返回當前的錯誤輸出的過程 (STDERR)。
     * @return string
     */
    public function getErrorOutput()
    {// 獲取錯誤輸出
        if ($this->outputDisabled) {
            throw new \LogicException('Output has been disabled.');
        }

        $this->requireProcessIsStarted(__FUNCTION__);// 開始程序

        $this->readPipes(false, '\\' === DS ? !$this->processInformation['running'] : true);// 讀取管道信息

        return $this->stderr;// 返回 錯誤字符串
    }

    /**
     * 以增量方式返回 errorOutput
     * @return string
     */
    public function getIncrementalErrorOutput()
    {// 增量方式 返回錯誤信息
        $this->requireProcessIsStarted(__FUNCTION__);

        $data = $this->getErrorOutput();

        $latest = substr($data, $this->incrementalErrorOutputOffset);

        if (false === $latest) {
            return '';
        }

        $this->incrementalErrorOutputOffset = strlen($data);

        return $latest;
    }// 同上的 普通信息輸出

    /**
     * 清空 errorOutput
     * @return Process
     */
    public function clearErrorOutput()
    {
        $this->stderr                       = '';
        $this->incrementalErrorOutputOffset = 0;

        return $this;
    }// 清空 錯誤 信息

    /**
     * 獲取退出碼
     * @return null|int
     */
    public function getExitCode()
    {// 獲取 退出碼
        if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
            throw new \RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
        }
// 獲取退出碼
        $this->updateStatus(false);//更新狀態

        return $this->exitcode;// 退出
    }

    /**
     * 獲取退出文本
     * @return null|string
     */
    public function getExitCodeText()
    {
        if (null === $exitcode = $this->getExitCode()) {
            return null;
        }

        return isset(self::$exitCodes[$exitcode]) ? self::$exitCodes[$exitcode] : 'Unknown error';
    }// 獲取退出 文本提示

    /**
     * 檢查是否成功
     * @return bool
     */
    public function isSuccessful()
    {
        return 0 === $this->getExitCode();
    }// 如果正常退出 爲0 就是 成功了

    /**
     * 是否未捕獲的信號已被終止子進程
     * @return bool
     */
    public function hasBeenSignaled()
    {
        $this->requireProcessIsTerminated(__FUNCTION__);

        if ($this->isSigchildEnabled()) {
            throw new \RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
        }

        $this->updateStatus(false);

        return $this->processInformation['signaled'];
    }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章