http协议 message返回问题

CodeAnti

start.php

<?php 
use \Workerman\Worker;
use \Workerman\WebServer;
use \GatewayWorker\Gateway;
use \GatewayWorker\BusinessWorker;
use \Workerman\Autoloader;

// 自动加载类
require_once __DIR__ . '/../../Workerman/Autoloader.php';
Autoloader::setRootPath(__DIR__);

// gateway 进程
$gateway = new Gateway("http://0.0.0.0:8585");
// 名称,以便status时查看方便
$gateway->name = 'HouseholdGateway';
// 开启的进程数,建议与cpu核数相同
$gateway->count = 4;
// 分布式部署时请设置成内网ip(非127.0.0.1)
$gateway->lanIp = '127.0.0.1';
// 内部通讯起始端口,假如$gateway->count=4,起始端口为4000
// 则一般会使用4001 4002 4003 4004 4个端口作为内部通讯端口 
$gateway->startPort = 4000;
// 心跳间隔
$gateway->pingInterval = 10;
// 心跳数据
$gateway->pingData = '{"type":"ping"}';

// bussinessWorker 进程
$worker = new BusinessWorker();
// worker名称
$worker->name = 'HouseholdBusinessWorker';
// bussinessWorker进程数量
$worker->count = 4;

Event.php

public static function onMessage($client_id, $message)
   {    
        //judgement the 
        if(empty($message)){
              $returnMessage = echoJson("300","no any params");
              Gateway::sendToClient($client_id,$returnMessage);
        }else{
              file_put_contents("message.txt",$message);
        }
   }

用的http协议,此处返回的message包含了头信息,而不是单纯的json,使得无法直接用json_decode解析,请问框架就是这样设计的,还是我搞错了

3383 1 0
1个回答

walkor

gateway/Worker 一般用于长连接应用。gateway很少用http协议的。
http协议的话 onMessage中会包含http头

  • 暂无评论
年代过于久远,无法发表回答
🔝