解决:PHP Fatal error: Uncaught Swoole\Error: operation not support (reactor is not ready)

报这个错是因为没有用协程方式运行脚本,而直接用了php运行,需要在代码外面套个go(function(){ …这里写内容},才能正常运行!

dbSource = new Swoole\Coroutine\MySQL();
        $this->dbConfig = [
            'host' => '127.0.0.1',
            'port' => '3306',
            'user' => 'root',
            'password' => '123456',
            'database' => 'testSwo',
            'charset' => 'utf8'
        ];

    }

    /**
     * @Notes:mysql执行
     * @Interface execute
     * @param $id
     * @param $username
     * @return bool
     * @Time: 2020/4/3   下午5:48
     */
    public function execute($id,$username){
        go(function () use($id){
            //connect
            $this->dbSource->connect($this->dbConfig);
            $sql = "select * from user where id = ".$id;
            $res = $this->dbSource->query($sql);
            if($res === false){
                var_dump("error");
            }
            var_dump($res);
            $this->dbSource->close();
        });
    }
}

$obj = new AysMysql();
$obj->execute(2,'张三');
解决:PHP Fatal error: Uncaught Swoole\Error: operation not support (reactor is not ready)_第1张图片
image.png

解决:PHP Fatal error: Uncaught Swoole\Error: operation not support (reactor is not ready)_第2张图片
image.png

你可能感兴趣的:(解决:PHP Fatal error: Uncaught Swoole\Error: operation not support (reactor is not ready))