'127.0.0.1', 'port' => 6379, 'passwd' => '', 'prefix' => 'ntp-' ); private function isHost($host) { // 判断host是否合法 preg_match('/^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/', $host, $match); if (count($match) !== 0) { // 域名 if (!is_numeric(substr($host, -1))) { return true; } // 域名最后一位不为数字 } if (filter_var($host, FILTER_VALIDATE_IP)) { // IP地址 return true; } return false; } 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 getRedisData($host) { // 查询Redis缓存,不存在返回NULL $redis = new Redis(); $redis->connect($this->redisSetting['host'], $this->redisSetting['port']); if ($this->redisSetting['passwd'] != '') { $redis->auth($this->redisSetting['passwd']); } $redisKey = $this->redisSetting['prefix'] . $host; $redisValue = $redis->exists($redisKey) ? $redis->get($redisKey) : NULL; return $redisValue; } private function setRedisData($host, $data, $cacheTTL) { // 写入信息到Redis缓存 $redis = new Redis(); $redis->connect($this->redisSetting['host'], $this->redisSetting['port']); if ($this->redisSetting['passwd'] != '') { $redis->auth($this->redisSetting['passwd']); } $redisKey = $this->redisSetting['prefix'] . $host; $redis->set($redisKey, $data); // 写入数据库 $redis->pexpire($redisKey, $cacheTTL); // 设置过期时间 } private function getNtpStatus($host) { // 获取NTP服务器状态 $html = $this->curlPost('https://servertest.online/ntp', array( 'a' => $host, 'c' => 'Query+both' )); preg_match('/<\/form>[\s\S]+