open('./db/ntpServer.db'); // NTP服务器数据库 } } class ntpList { private function getListName($list_id) { // 获取对应组的名称 $db = new ntpDB; $res = $db->query('SELECT * FROM `ntp_list` WHERE id=' . $list_id . ';'); return $res->fetchArray(SQLITE3_ASSOC)['name']; } public function getNtpList() { // 获取所有NTP服务器地址 $db = new ntpDB; $res = $db->query('SELECT * FROM `ntp_host`;'); while ($row = $res->fetchArray(SQLITE3_ASSOC)) { $index = $row['list_id']; unset($row['list_id']); $data[$this->getListName($index)][] = $row; } return $data; } } class ntpCheck { private function formatOffset($str) { // 格式化Offset $num = number_format($str, 6) * 1000; // s -> ms $str = sprintf("%1\$.3f", $num); // 补零到小数点后3位 if ($num > 0) { $str = '+' . $str; // 正数前加+ } return $str . 'ms'; } private function curlPost($url, $data) { // curl模拟post操作 40s超时 $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 40); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $content = curl_exec($curl); curl_close($curl); return $content; } private function getNtpStatus($host) { // 获取NTP服务器状态 $html = $this->curlPost('https://servertest.online/ntp', array( 'a' => $host, 'c' => 'Query+both' )); preg_match('/<\/form>[\s\S]+