'URL is required', 'status' => 0, 'time' => 0]); exit; } // Validate URL format if (!filter_var($url, FILTER_VALIDATE_URL)) { echo json_encode(['error' => 'Invalid URL format', 'status' => 0, 'time' => 0]); exit; } $start = microtime(true); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, 'NativeUptimeMonitor/2.0'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $response = curl_exec($ch); $info = curl_getinfo($ch); $error = curl_error($ch); curl_close($ch); $end = microtime(true); $timeMs = round(($end - $start) * 1000); // Determine final status code $statusCode = $info['http_code']; if ($error) { echo json_encode([ 'url' => $url, 'status' => 0, // 0 for network/timeout error 'time' => $timeMs, 'error_detail' => $error ]); } else { echo json_encode([ 'url' => $url, 'status' => $statusCode, 'time' => $timeMs ]); } ?>