[李景山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'];
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值