0

swoole的websocket在$ws->on('open'中向push就断开连接了,原生php没问题不会断开,swoole代码写在tp3.2框架类中的方法就不行
`
class CliAction{

public function index(){
    $redis=new Redis;
    $redis->pconnect('127.0.0.1', 6379); 
    $redis->del('set'); 
    $pool = new RedisPool();

    //创建websocket服务器对象,监听0.0.0.0:9502端口
    $ws = new swoole_websocket_server("0.0.0.0", 9502);

    //监听WebSocket连接打开事件
    $ws->on('open', function ($ws, $request)use($pool) {
        $redis = $pool->get();
        var_dump($request->fd, $request->get, $request->server);
        $redis->sadd('set',$request->fd);
        $ws->push($request->fd, "服务器回复连接成功,redis保存连接".($redis->sismember('set',$request->fd)? '成功':'失败')); //加了这句就在此断开连接
        $pool->put($redis);
    });`
11月7日提问
0 个回答

撰写答案

推广链接