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
亲爱的同学您好。请把第二张图 截全点。我看看上面是什么。
122019-06-25 -
hen_nam
2021-08-07
用 \think\facade\Config::get() 代替
012021-08-08
相似问题