swoole 事件无返回

浏览:1686 发布日期:2018/07/30 分类:ThinkPHP5专区
环境: tp5.1.20,topthink/think-swoole (v2.0.12)

问题: swoole作为tcp服务,运行 php think swoole:server 后, 执行receive事件没有收到client端发送的数据, connect、close事件可以看到。

config/swoole_server.php的代码如下:return [
    // 扩展自身配置
    'host'         => '0.0.0.0', // 监听地址
    'port'         => 9508, // 监听端口
    'type'         => '', // 服务类型 支持 socket http server
    'mode'         => SWOOLE_PROCESS,
    'socket_type'  => SWOOLE_SOCK_TCP,
    'swoole_class' => '', // 自定义服务类名称

    // 可以支持swoole的所有配置参数
    'daemonize'    => false,
    'pid_file'     => Env::get('runtime_path') . 'swoole_server.pid',
    'log_file'     => Env::get('runtime_path') . 'swoole_server.log',

    // 事件回调定义
    'onOpen'       => function ($server, $request) {
        echo "server: handshake success with fd{$request->fd}\n";
    },

    'onMessage'    => function ($server, $frame) {
        echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
        $server->push($frame->fd, "this is server");
    },

    'onRequest'    => function ($request, $response) {
        $response->end("<h1>Hello Swoole. #" . rand(1000, 9999) . "</h1>");
    },

     'onPacket'    => function ($fd, $response) {
        echo "onPacket" ;
    },

   
    'onConnect'    => function ($fd, $serv) {
        echo "连接成功\n" ;
    },

     'onReceive'    => function ($server, $fd, $reactor_id, $data) {
        echo "接受到了数据...\n" ;
        var_dump($data) ;

    },

    'onClose'      => function ($ser, $fd) {
        echo "client {$fd} closed\n";
    },
];
传不了图,输出的文字如下:Starting swoole server...
Swoole socket server started: <0.0.0.0:9508>
You can exit with `CTRL-C`
连接成功
client 1 closed
最佳答案
评论( 相关
后面还有条评论,点击查看>>