php使用gatewayworker,tp5.1中gatewayworker简单使用

1、composer安装thinkphp

composer create-project topthink/think=5.1.* tp5

2、进入tp5根目录

3、安装gatewayworker

composer require workerman/gateway-worker

5、将Applications/Yourapp复制到tp5目录application中,并更改名字为push(这里随意)

6、将start.php复制到tp5根目录下,并更改start.php最后的foreach路径

7、根目录中启动 php start.php start

20ab24f3bffbd65c08f8991350c3c59b.png

8、简单使用

a)前端进行登录并请求后端绑定 用户登录后初始化以及绑定client_id(前端监听ws://xxx.xxx.xxx.xxx:8282端口,代码省略)

public function bind()

{

// 设置GatewayWorker服务的Register服务ip和端口,请根据实际情况改成实际值

\GatewayWorker\Lib\Gateway::$registerAddress = '127.0.0.1:1238';

$this->uid = '111'; //假数据

$client_id = Request::param('client_id');

// client_id与uid绑定

\GatewayWorker\Lib\Gateway::bindUid($client_id, $uid);

// 加入某个群组(可调用多次加入多个群组)

//$group_id = $this->groupId;

//Gateway::joinGroup($client_id, $group_id);

}

b)前端进行操作(节目投票、聊天等等)

c)调用后端对应方法

d)一系列业务操作后,推送

$message = ['code'=>0,'msg'=>'投票成功'];

\GatewayWorker\Lib\Gateway::$registerAddress = '127.0.0.1:1238';

\GatewayWorker\Lib\Gateway::sendToUid($this->uid,json_encode($message)); //这一步可以省略

备注:有错误或者遗漏敬请指出

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值