swoole_server->connection_info
swoole_server->connection_info 函数用来获取连接的信息
function swoole_server->connection_info(int $fd, int $from_id, bool $ignore_close = false)
- 如果传入的fd存在,将会返回一个数组
- 连接不存在或已关闭,返回false
- 第3个参数设置为true,即使连接关闭也会返回连接的信息
需要swoole-1.5.8以上版本
connect_time, last_time 在v1.6.10+可用
connection_info可用于UDP服务器,但需要传入from_id参数
$fdinfo = $serv->connection_info($fd); var_dump($fdinfo); array(5) { ["from_id"]=>int(3) ["server_fd"]=>int(14) ["server_port"]=>int(9501) ["remote_port"]=>int(19889) ["remote_ip"]=>string(9) "127.0.0.1" ["connect_time"]=>int(1390212495) ["last_time"]=>int(1390212760) } $udp_client = $serv->connection_info($fd, $from_id); var_dump($udp_client);
- from_id 来自哪个reactor线程
- server_fd 来自哪个server socket 这里不是客户端连接的fd
- server_port 来自哪个Server端口
- remote_port 客户端连接的端口
- remote_ip 客户端连接的ip
- connect_time 连接到Server的时间,单位秒
- last_time 最后一次发送数据的时间,单位秒