Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 810c814

Browse files
committed
✨ 将http服务器放到第一个加载,为api做准备
1 parent a3520b6 commit 810c814

File tree

2 files changed

+47
-45
lines changed

2 files changed

+47
-45
lines changed

inc/server.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ public function startserver() {
108108
$url = $request->server['request_uri']."?".$request->server['query_string'];
109109
}
110110
//真的会有启动器不带ua的啊,太神奇了
111-
if(!isset($request->server['user-agent'])){
112-
$request->server['user-agent'] = "other";
113-
}
111+
$request->server['user-agent'] = $request->server['user-agent'] ?? "other";
114112
mlog(" Serve {$code} | {$request->server['remote_addr']} | {$request->server['server_protocol']} | {$url} | {$request->header['user-agent']};") ;
115113
});
116114
$server->handle('/measure', function ($request, $response) {

main.php

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
use function Swoole\Timer;
55
declare(ticks=1)
66
date_default_timezone_set('Asia/Shanghai');
7-
set_time_limit(0);
8-
ini_set('memory_limit', '-1');
97
require './config.php';
108
const PHPOBAVERSION = '1.3.0';
119
const VERSION = '1.10.4';
1210
global $DOWNLOAD_DIR;
1311
$DOWNLOAD_DIR = $config['file']['cache_dir'];
1412
const USERAGENT = 'openbmclapi-cluster/' . VERSION . ' ' . 'PHP-OpenBmclApi/'.PHPOBAVERSION;
15-
const OPENBMCLAPIURL = 'openbmclapi.bangbang93.com';
13+
const OPENBMCLAPIURL = 'openbmclapi.staging.bangbang93.com';
1614
$list = glob('inc/*.php');
1715
foreach ($list as $file) {
1816
require $file;
@@ -55,7 +53,49 @@ function registerSigintHandler() {
5553
});
5654
registerSigintHandler();
5755
mlog("Timer start on ID{$tokentimerid}",1);
58-
56+
//建立socketio连接主控
57+
$socketio = new socketio(OPENBMCLAPIURL,$tokendata['token'],$config['advanced']['keepalive']);
58+
mlog("正在连接主控");
59+
Coroutine::create(function () use ($socketio){
60+
$socketio->connect();
61+
});
62+
Coroutine::sleep(1);
63+
//获取证书
64+
$socketio->ack("request-cert");
65+
Coroutine::sleep(1);
66+
$allcert = $socketio->Getcert();
67+
//写入证书并且是否损坏
68+
if (!file_exists('./cert/'.$config['cluster']['CLUSTER_ID'].'.crt') && !file_exists('./cert/'.$config['cluster']['CLUSTER_ID'].'.key')) {
69+
mlog("正在获取证书");
70+
if (!file_exists("./cert")) {
71+
mkdir("./cert",0777,true);
72+
}
73+
mlog("已获取证书,到期时间{$allcert['0']['1']['expires']}");
74+
$cert = fopen('./cert/'.$config['cluster']['CLUSTER_ID'].'.crt', 'w');
75+
$Writtencert = fwrite($cert, $allcert['0']['1']['cert']);
76+
fclose($cert);
77+
$cert = fopen('./cert/'.$config['cluster']['CLUSTER_ID'].'.key', 'w');
78+
$Writtencert = fwrite($cert, $allcert['0']['1']['key']);
79+
fclose($cert);
80+
}
81+
$crt = file_get_contents('./cert/'.$config['cluster']['CLUSTER_ID'].'.crt');
82+
if ($crt!== $allcert['0']['1']['cert']) {
83+
mlog("证书损坏/过期");
84+
mlog("已获取新的证书,到期时间{$allcert['0']['1']['expires']}");
85+
$cert = fopen('./cert/'.$config['cluster']['CLUSTER_ID'].'.crt', 'w');
86+
$Writtencert = fwrite($cert, $allcert['0']['1']['cert']);
87+
fclose($cert);
88+
$cert = fopen('./cert/'.$config['cluster']['CLUSTER_ID'].'.key', 'w');
89+
$Writtencert = fwrite($cert, $allcert['0']['1']['key']);
90+
fclose($cert);
91+
}
92+
//启动http服务器
93+
global $httpserver;
94+
$httpserver = new fileserver($config['cluster']['host'],$config['cluster']['port'],$config['cluster']['CLUSTER_ID'].'.crt',$config['cluster']['CLUSTER_ID'].'.key',$config['cluster']['CLUSTER_SECRET']);
95+
Coroutine::create(function () use ($config,$httpserver){
96+
$httpserver->startserver();
97+
});
98+
5999
//下载文件列表
60100
$cluster = new cluster($tokendata['token'],VERSION);
61101
$files = $cluster->getFileList();
@@ -69,6 +109,7 @@ function registerSigintHandler() {
69109
elseif($config['file']['check'] == "exists"){
70110
$Missfile = $FilesCheck->FilesCheckerexists();
71111
}
112+
//循环到没有Missfile这个变量
72113
if (is_array($Missfile)){
73114
mlog("缺失/损坏".count($Missfile)."个文件");
74115
while(is_array($Missfile)){
@@ -100,44 +141,7 @@ function registerSigintHandler() {
100141
}
101142
global $shouldExit;
102143
if (!is_array($Missfile) && !$shouldExit){//判断Missfile是否为空和是否是主动退出
103-
$socketio = new socketio(OPENBMCLAPIURL,$tokendata['token'],$config['advanced']['keepalive']);
104-
mlog("正在连接主控");
105-
Coroutine::create(function () use ($socketio){
106-
$socketio->connect();
107-
});
108-
Coroutine::sleep(1);
109-
$socketio->ack("request-cert");
110-
Coroutine::sleep(1);
111-
$allcert = $socketio->Getcert();
112-
if (!file_exists('./cert/'.$config['cluster']['CLUSTER_ID'].'.crt') && !file_exists('./cert/'.$config['cluster']['CLUSTER_ID'].'.key')) {
113-
mlog("正在获取证书");
114-
if (!file_exists("./cert")) {
115-
mkdir("./cert",0777,true);
116-
}
117-
mlog("已获取证书,到期时间{$allcert['0']['1']['expires']}");
118-
$cert = fopen('./cert/'.$config['cluster']['CLUSTER_ID'].'.crt', 'w');
119-
$Writtencert = fwrite($cert, $allcert['0']['1']['cert']);
120-
fclose($cert);
121-
$cert = fopen('./cert/'.$config['cluster']['CLUSTER_ID'].'.key', 'w');
122-
$Writtencert = fwrite($cert, $allcert['0']['1']['key']);
123-
fclose($cert);
124-
}
125-
$crt = file_get_contents('./cert/'.$config['cluster']['CLUSTER_ID'].'.crt');
126-
if ($crt!== $allcert['0']['1']['cert']) {
127-
mlog("证书损坏/过期");
128-
mlog("已获取新的证书,到期时间{$allcert['0']['1']['expires']}");
129-
$cert = fopen('./cert/'.$config['cluster']['CLUSTER_ID'].'.crt', 'w');
130-
$Writtencert = fwrite($cert, $allcert['0']['1']['cert']);
131-
fclose($cert);
132-
$cert = fopen('./cert/'.$config['cluster']['CLUSTER_ID'].'.key', 'w');
133-
$Writtencert = fwrite($cert, $allcert['0']['1']['key']);
134-
fclose($cert);
135-
}
136-
global $httpserver;
137-
$httpserver = new fileserver($config['cluster']['host'],$config['cluster']['port'],$config['cluster']['CLUSTER_ID'].'.crt',$config['cluster']['CLUSTER_ID'].'.key',$config['cluster']['CLUSTER_SECRET']);
138-
Coroutine::create(function () use ($config,$httpserver){
139-
$httpserver->startserver();
140-
});
144+
//enable节点
141145
$socketio->enable($config['cluster']['public_host'],$config['cluster']['public_port'],$config['cluster']['byoc']);
142146
}
143147
});

0 commit comments

Comments
 (0)