|
@ -20,27 +20,32 @@ class kmsCheck { |
|
|
|
|
|
|
|
|
public function kmsStatus($host, $port) { |
|
|
public function kmsStatus($host, $port) { |
|
|
$server = $host . ':' . $port; |
|
|
$server = $host . ':' . $port; |
|
|
|
|
|
$redis = new redisCache('kms'); |
|
|
|
|
|
$info = $redis->getData($server); // 查询缓存数据 |
|
|
|
|
|
if (!$info) { // 缓存未命中 |
|
|
$url = $this->api . 'check?host=' . $host . '&port=' . $port; |
|
|
$url = $this->api . 'check?host=' . $host . '&port=' . $port; |
|
|
$content = json_decode(file_get_contents($url), true); // 请求上游接口 |
|
|
$info = json_decode(file_get_contents($url), true); // 请求上游接口 |
|
|
switch ($content['status']) { |
|
|
$info['server'] = $server; |
|
|
|
|
|
switch ($info['status']) { |
|
|
case 'ok': |
|
|
case 'ok': |
|
|
return array( |
|
|
$info['online'] = true; |
|
|
'status' => 'ok', |
|
|
break; |
|
|
'online' => true, |
|
|
|
|
|
'server' => $server |
|
|
|
|
|
); |
|
|
|
|
|
case 'error': |
|
|
case 'error': |
|
|
return array( |
|
|
$info['online'] = false; |
|
|
'status' => 'ok', |
|
|
break; |
|
|
'online' => false, |
|
|
|
|
|
'server' => $server |
|
|
|
|
|
); |
|
|
|
|
|
default: |
|
|
default: |
|
|
return array( |
|
|
return array( |
|
|
'status' => 'error', |
|
|
'status' => 'error', |
|
|
'message' => 'Server error' |
|
|
'message' => 'Server error' |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
$info['status'] = 'ok'; |
|
|
|
|
|
unset($info['message']); |
|
|
|
|
|
$redis->setData($server, json_encode($info), 300); // 缓存5min |
|
|
|
|
|
} else { // 缓存命中 |
|
|
|
|
|
$info = json_decode($info, true); // 使用缓存数据 |
|
|
|
|
|
} |
|
|
|
|
|
return $info; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|