码迷,mamicode.com
首页 > Web开发 > 详细

[李景山php]每天TP5-20170125|thinkphp5-Process.php-7

时间:2016-12-28 13:05:16      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:thinkphp5

    /**
     * 获取输入
     * @return null|string
     */
    public function getInput()
    {
        return $this->input;
    }// 获取输入信息

    /**
     * 设置输入
     * @param mixed $input
     * @return self
     */
    public function setInput($input)
    {
        if ($this->isRunning()) {
            throw new \LogicException(‘Input can not be set while the process is running.‘);
        }

        $this->input = Utils::validateInput(sprintf(‘%s::%s‘, __CLASS__, __FUNCTION__), $input);

        return $this;
    }// 属于信息 设置

    /**
     * 获取proc_open的选项
     * @return array
     */
    public function getOptions()
    {
        return $this->options;
    }// 获取 选项

    /**
     * 设置proc_open的选项
     * @param array $options
     * @return self
     */
    public function setOptions(array $options)
    {
        $this->options = $options;

        return $this;
    }// 设置选项,这个设置,有点唐突哦

    /**
     * 是否兼容windows
     * @return bool
     */
    public function getEnhanceWindowsCompatibility()
    {
        return $this->enhanceWindowsCompatibility;
    }// 我就是说这个是 windows 兼容的 情况,一般不兼容这个鬼东西

    /**
     * 设置是否兼容windows
     * @param bool $enhance
     * @return self
     */
    public function setEnhanceWindowsCompatibility($enhance)
    {
        $this->enhanceWindowsCompatibility = (bool)$enhance;

        return $this;
    }// 设置 是否兼容 windows

    /**
     * 返回是否 sigchild 兼容模式激活
     * @return bool
     */
    public function getEnhanceSigchildCompatibility()
    {
        return $this->enhanceSigchildCompatibility;
    }// 是否子进程模式 激活

    /**
     * 激活 sigchild 兼容性模式。
     * @param bool $enhance
     * @return self
     */
    public function setEnhanceSigchildCompatibility($enhance)
    {
        $this->enhanceSigchildCompatibility = (bool)$enhance;

        return $this;
    }// 激活它

    /**
     * 是否超时
     */
    public function checkTimeout()
    {// 是否超时
        if ($this->status !== self::STATUS_STARTED) {
            return;
        }// 类型

        if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
            $this->stop();
// 如果 时间 溢出
            throw new ProcessTimeoutException($this, ProcessTimeoutException::TYPE_GENERAL);
        }// 抛出异常

        if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) {
            $this->stop();

            throw new ProcessTimeoutException($this, ProcessTimeoutException::TYPE_IDLE);
        }// 抛出异常2
    }

    /**
     * 是否支持pty
     * @return bool
     */
    public static function isPtySupported()
    {// 是否支持 pty
        static $result;// 静态结果

        if (null !== $result) {// 有结果,就直接返回
            return $result;
        }

        if (‘\\‘ === DS) {// 在 windows 下呢
            return $result = false;// 返回 错误信息
        }

        $proc = @proc_open(‘echo 1‘, [[‘pty‘], [‘pty‘], [‘pty‘]], $pipes);// 打开类似于管道方式
        if (is_resource($proc)) {// 如果是资源
            proc_close($proc);// 关闭资源

            return $result = true;
        }

        return $result = false;
    }


本文出自 “专注php 群号:414194301” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1886750

[李景山php]每天TP5-20170125|thinkphp5-Process.php-7

标签:thinkphp5

原文地址:http://jingshanls.blog.51cto.com/3357095/1886750

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!