config配置文件找不到

来源:8-12 赛事直播在线用户处理 - redis方案(一)

阿里奇奇

2019-03-26

图片描述
图片描述图片描述图片描述

class Ws{
CONST HOST = “0.0.0.0”;
CONST PORT = 8811;

public $ws = null;
public function __construct(){
    $this->ws = new Swoole_websocket_server(self::HOST,self::PORT);
    $this->ws->set(
        [
            'enable_static_handler'=>true,
            'document_root'=>'/data/wwwroot/swoole.devilgod.cn/public/static',
            'worker_num' => 1,
            'task_worker_num'=>1,
        ]
    );

    $this->ws->on('open',[$this,'onOpen']);
    $this->ws->on('message',[$this,'onMessage']);
    $this->ws->on('workerstart',[$this,'onWorkerStart']);
    $this->ws->on('request',[$this,'onRequest']);
    $this->ws->on('task',[$this,'onTask']);
    $this->ws->on('finish',[$this,'onFinish']);
    $this->ws->on('close',[$this,'onClose']);

    $this->ws->start();
}

public function onWorkerStart($server,$worker_id){
    define('APP_PATH',__DIR__.'/../application/');
    //加载框架里面的文件
    require __DIR__.'/../thinkphp/base.php';
}

//request 回调
public function onRequest($request,$response){
    $_SERVER = [];
    if(isset($request->server))
    {
        foreach($request->server as $k => $v){
            $_SERVER[strtoupper($k)] = $v;
        }
    }

    if(isset($request->header)){
        foreach($request->header as $k=>$v){
            $_SERVER[strtoupper($k)] = $v;
        }
    }

    $_GET = [];
    if(isset($request->get)){
        foreach($request->get as $k=>$v){
            $_GET[$k] = $v;
        }
    }

    $_FILES = [];
    if(isset($request->files)){
        foreach($request->files as $k=>$v){
            $_FILES[$k] = $v;
        }
    }

    $_POST = [];
    if(isset($request->post)){
        foreach($request->post as $k=>$v){
            $_POST[$k] = $v;
        }
    }

    $_POST['http_server'] = $this->ws;
    ob_start();
    // 执行应用并响应
    think\Container::get('app',[APP_PATH])->run()->send();

// think\Container::get(‘app’)->run()->send();

    $res = ob_get_contents();
    if (ob_get_length() > 0 ) {
        ob_end_clean();
    }
    $response->end($res);
}

public function onTask($serv,$taskId,$workerId,$data){
    //分发 task 任务机制,让不同的任务 走不同的逻辑
    $obj = new app\common\lib\task\Task;

    //自己判断  method data的等数据是否存在???
    $method = $data['method'];
    $flag = $obj->$method($data['data']);

// try{
// $sms = new Sms();
// $response = sms−>sendverify(sms->send_verify(sms>sendverify(data[‘phone’],$data[‘code’]);
// }catch(\Exception KaTeX parse error: Expected '}', got 'EOF' at end of input: … var_dump(e->getMessage());
// }
return $flag;
}

public function onFinish($serv,$taskId,$data){
    echo "taskId:{$taskId}\n";
    echo "finish-data-success:{$data}\n";
}

/*
  • 监听ws连接事件

  • */
    public function onOpen(ws,ws,ws,request){

    //fd redis [1,2]
    \app\common\redis\Predis::getInstance()->sAdd(‘live_game_key’,request−>fd);vardump(request->fd); var_dump(request>fd);vardump(request->fd);

}
写回答

2回答

singwa

2019-03-26

亲爱的同学您好。请把第二张图 截全点。我看看上面是什么。

1
2
EMP周
我也遇到咯。你怎么解决的
2019-06-25
共2条回复

hen_nam

2021-08-07

用 \think\facade\Config::get() 代替


0
1
hen_nam
抱歉,这样也不行
2021-08-08
共1条回复

Swoole入门到实战打造高性能赛事直播平台

swoole创始人推荐,借助Swoole打造高性能直播平台

2228 学习 · 1062 问题

查看课程