资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php使用长连接

  1. 安装:
    composer  require  workerman/gateway-worker
  2. 服务端:
    startPort = 30000;
    $gateway->count = 4;
    $gateway->name = 'gateway';
    $gateway->registerAddress = '127.0.0.1:1234';
    $business = new BusinessWorker();
    $business->count = 4;
    $business->registerAddress = '127.0.0.1:1234';
    $register = new Register('text://0.0.0.0:1234');
    $register->name = 'register';
    class Events{
    public static function onConnect($client_id){
        $arr = array(
                'remote_ip'=>$_SERVER['REMOTE_ADDR'],
                'remote_port'=>$_SERVER['REMOTE_PORT'],
                'gate_ip'=>$_SERVER['GATEWAY_ADDR'],
                'gate_port'=>$_SERVER['GATEWAY_PORT'],
                'client_id'=>$_SERVER['GATEWAY_CLIENT_ID']
            );
        $ret = json_encode($arr);
        return GateWay::sendToCurrentClient($ret);
    }
    public static function onMessage($client_id, $message){
        return GateWay::sendToCurrentClient($message);
    }
    public static function onClose($client_id){
       GateWay::sendToAll("client[$client_id] logout\n");
    }
    }
    Worker::runAll();
  3. 客户端:
    
    
    
    
    Document
    
    
    
    
  4. 测试:
    php使用长连接

文章名称:php使用长连接
链接分享:http://cdkjz.cn/article/pspgcc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220