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

发布于 2015-08-09 09:43:50 | 238 次阅读 | 评论: 0 | 来源: 网络整理

回调函数中经常看到它。

  • from_id是来自于哪个reactor线程
  • fd是tcp连接的文件描述符

调用swoole_server->send/swoole_server->close函数需要传入$fd参数才能被正确的处理。如果业务中需要发送广播,需要用apc/redis/memcache/swoole_table将fd的值保存起来。

1.6.0以上版本不再需要from_id参数,swoole本身提供了ConnectionList可以查询到当前所有的fd和对应from_id
1.7.10以上版本,fd不再是文件描述符。fd是一个自增数字,范围是 1 ~ 1600万

function my_onReceive($serv, $fd, $from_id, $data)  {
    //向Connection发送数据
    $serv->send($fd, 'Swoole: '.$data); 

    //关闭Connection
    $serv->close($fd); 
}
最新网友评论  共有(0)条评论 发布评论 返回顶部

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