0
$server = new Swoole\WebSocket\Server("0.0.0.0", 9501);

$server->on('open', function (Swoole\WebSocket\Server $server, $request) {
    echo "server: handshake success with fd{$request->fd}\n";
});
//心跳等配置
$server->set([
    'heartbeat_check_interval' => 5,
    'heartbeat_idle_time' => 10,
]);

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

$server->on('close', function ($ser, $fd) {
    echo "client {$fd} closed\n";
});

//我想加一个类似心跳检测的功能,就是启动后就轮询执行的功能 我要怎么加呢?
$server->start();
11月13日提问
1 个回答
0

你现在加的参数就是啊。。。
'heartbeat_idle_time' => 10一个连接如果10秒内未向服务器发送任何数据,此连接将被强制关闭
'heartbeat_check_interval' => 5每5秒遍历一次

撰写答案

推广链接