作者:手机用户2602919763 | 来源:互联网 | 2023-06-19 15:47
服务端Swoole_Server开启了心跳检测(heartbeat_check_interval),12345678 $serv->set([ //'daemonize'
服务端Swoole_Server开启了心跳检测(heartbeat_check_interval),
1 2 3 4 5 6 7 8
| $serv->set([
//'daemonize' => 1, // 进入守护进程 防止ssh终端退出后,程序将被终止运行
'worker_num' => 4, // 开启进程数
'heartbeat_check_interval' => 10, // * 服务器定时检测在线列表的时间
'heartbeat_idle_time' => 20, // 连接最大的空闲时间 (如果最后一个心跳包的时间与当前时间之差超过这个值,则认为该连接失效)
'log_file' => 'swoole.log',
'max_connection' => 10000 // 最多允许tcp链接数
]); |
20秒后踢掉了客户端。
客户端:client.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| $client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
$this->server = $client;
$client->on('connect', function($cli) {
$data = [
'companyid'=>$this->config['companyid'],
'companykey'=>$this->config['companykey']
];
$cli->send(json_encode($data));
});
//注册数据接收回调
$client->on('receive', function($cli, $data) {
echo "Received: " . $data;
$this->redis()->rpush('notifyClient',$data);
// 记录tcp数据
$this->redis()->rpush('log_tcp',$data);
});
$client->on('error', function($cli) {
echo "Connect failed\r\n\r\n";
});
$client->on('close', function($cli) {
echo "Connection close\r\n\r\n";
});
$client->connect('ip', 9501, true); |
问题是怎么在客户端做心跳回应?