Laravel使用hhxsv5/laravel-s(Swoole适配器)实现广播

1.hhxsv5/laravel-s适配器github地址: 

https://github.com/hhxsv5/laravel-s

2.主要代码

        /**@var \Swoole\Http\Server|\Swoole\WebSocket\Server $swoole */
        $swoole = app('swoole');
        // $swoole->ports:遍历所有Port对象,https://wiki.swoole.com/#/server/properties?id=ports
        $port = $swoole->ports[1]; // 获得`Swoole\Server\Port`对象,$port[0]是主服务器的端口
        foreach ($port->connections as $fd) { // 遍历所有连接
            // $swoole->send($fd, 'Send tcp message');
            // if($swoole->isEstablished($fd)) {
            //     $swoole->push($fd, 'Send websocket message');
            // }
        }

3.说明

  • 需要使用swoole代替php-fpm,也就是说需要修改nginx配置文件,详见github上的文档.
  • 上述代码$port = $swoole->ports[1];中的1为文档示例,需要根据实际情况填写,以确定需要广播的websocket(端口)链接.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值