$item) fputcsv($output, [$index + 1, $item['url'], $item['status_text'], $item['http_code'], $item['response_time'], $item['content_length'], $item['timestamp']]); fclose($output); exit; } elseif ($exportType === 'json') { header('Content-Type: application/json'); header('Content-Disposition: attachment; filename="' . $filename . '.json"'); echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } } } function checkUrls($urls) { $results = []; foreach ($urls as $url) { if (!preg_match('/^https?:\/\//', $url)) $url = 'http://' . $url; $results[] = checkUrlStatus($url); } return $results; } function checkUrlStatus($url) { $startTime = microtime(true); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $errno = curl_errno($ch); $error = curl_error($ch); $responseTime = round((microtime(true) - $startTime) * 1000, 2); $contentLength = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); curl_close($ch); if ($errno !== 0) { $status = 'error'; $statusText = '连接失败'; } elseif ($httpCode >= 200 && $httpCode < 300) { $status = 'success'; $statusText = '在线'; } elseif ($httpCode >= 300 && $httpCode < 400) { $status = 'warning'; $statusText = '重定向'; } elseif ($httpCode >= 400 && $httpCode < 500) { $status = 'warning'; $statusText = '客户端错误'; } else { $status = 'error'; $statusText = '服务器错误'; } return [ 'url' => $url, 'status' => $status, 'status_text' => $statusText, 'http_code' => $httpCode, 'response_time' => $responseTime, 'content_length' => $contentLength !== null ? $contentLength : 'N/A', 'timestamp' => date('Y-m-d H:i:s'), 'error_message' => $error ]; } ?> 网站状态检测工具

网站状态检测工具

检测结果: 总计 个正常, 个警告, 个错误,共 个网站
$item): ?>
序号 网址 状态 HTTP状态码 响应时间 内容大小 检测时间
ms