- 项目目录
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/aa9baad0ab1e5bc25dd4d61b1d7d4669.png)
项目业务目录可以跟worker目录分开部署在不同的服务器,worker独立部署,只负责客户端的推送消息。 - worker服务端修改start_gateway.php 文件。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/989a2a7d99dec8d87f7959b5c83b79f0.png)
- tcp协议改为websocket协议,服务器注册地址是:127.0.0.1:1238 注意,后面GatewayClient连接时需要使用
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/df37b8ffc5ed749567845f07dcfaf219.png)
- GatewayClient文件放入项目目录
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/cf99295e056420cf6c5d386f5bb27dd4.png)
- index控制器引入GatewayClient
<?php
namespace app\index\controller;
require_once 'Gateway.php';
// GatewayClient 3.0.0版本开始要使用命名空间
use GatewayClient\Gateway;
class Index
{
public function index()
{
// 设置GatewayWorker服务的Register服务ip和端口,请根据实际情况改成实际值(ip不能是0.0.0.0)
Gateway::$registerAddress = '127.0.0.1:1238';
$data = '99999';
$uid = '7f0000010b5400000001';
$res = Gateway::sendToClient($uid, $data);
print_r($res);
// Gateway::sendToAll($data);
// 向任意uid的网站页面发送数据
// Gateway::sendToUid($uid, $message);
// // 向任意群组的网站页面发送数据
// Gateway::sendToGroup($group, $message);
}
}
- 需要做服务推送的时候,可向当前在线的用户推送信息。调用 GatewayClient中的方法,推送信息。