​​​​​

    public  function  workerStart($server,$worker_id){
        //支持热加载
        $config=Config::get_instance();
        $config->loadLazy();
        //连接redis、连接数据库

        go(function () {//创建协程环境
            $cli = new Swoole\Coroutine\Http\Client("127.0.0.1", 9600);
            $ret = $cli->upgrade("/");//升级的websocket
            if ($ret) {
//                while(true) {
                    $cli->push("hello");
                    var_dump($cli->recv());
                    //co::sleep(0.1);//每隔0.1秒,休眠函数
//                }
            }
        });

        //加载路由配置文件
        include_once APP_PATH.'/route.php';
    }

上图代码会报下图错

swoole学习笔记-IM-SERVER

下面代码不会报错

    public  function  workerStart($server,$worker_id){
        //支持热加载
        $config=Config::get_instance();
        $config->loadLazy();
        //连接redis、连接数据库

        go(function () {//创建协程环境
            $cli = new \Swoole\Coroutine\Http\Client("127.0.0.1", 9600);
            $ret = $cli->upgrade("/");//升级的websocket
            if ($ret) {
//                while(true) {
                    $cli->push("hello");
                    var_dump($cli->recv());
                    //co::sleep(0.1);//每隔0.1秒,休眠函数
//                }
            }
        });

        //加载路由配置文件
        include_once APP_PATH.'/route.php';
    }

 

测试IM redis swoole学习笔记-IM-SERVER

相关文章:

  • 2021-06-15
  • 2021-10-24
  • 2022-01-11
  • 2022-01-06
  • 2021-07-17
  • 2022-02-04
  • 2021-08-09
猜你喜欢
  • 2021-04-04
  • 2021-06-10
  • 2021-07-07
  • 2021-09-23
  • 2022-12-23
  • 2021-09-13
相关资源
相似解决方案