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';
}
上图代码会报下图错
下面代码不会报错
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