tp5.1 in gatewayworker simple to use

1, composer install thinkphp

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

2, into the root directory tp5

3, installation gatewayworker

composer require workerman/gateway-worker

4, download the official version of linux Demo: http://www.workerman.net/download

5. Copy the Applications / Yourapp to tp5 application directory and change the name to push (here arbitrarily)

6, copy start.php to the next tp5 root directory and change the last foreach path start.php

7, the root directory to start php start.php start

Start and stop commands: http://doc2.workerman.net/326106

8, simple to use

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)); //这一步可以省略

Note: There are errors or omissions please indicate

Guess you like

Origin www.cnblogs.com/L-ran/p/12149635.html