入门指引 Server Client Process AsyncIO Memory HttpServer WebSocket 高级 其他

发布于 2015-08-09 09:48:04 | 82 次阅读 | 评论: 0 | 来源: 网络整理

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 最后一次发送数据的时间,单位秒
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务