Skip to content

Instantly share code, notes, and snippets.

@akccakcctw
Last active July 15, 2024 08:16
Show Gist options
  • Save akccakcctw/e98b94c22e4a009330d6a9f988f09f19 to your computer and use it in GitHub Desktop.
Save akccakcctw/e98b94c22e4a009330d6a9f988f09f19 to your computer and use it in GitHub Desktop.
dns_lookup_time.php
<?php
$url = 'http://google.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 啟用 CURL 信息
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
// 啟用詳細的 CURL 信息
curl_setopt($ch, CURLOPT_VERBOSE, true);
// 執行 CURL 请求
curl_exec($ch);
// 獲取 CURL 傳輸信息
$info = curl_getinfo($ch);
if ($info === FALSE) {
echo 'CURL Error: ' . curl_error($ch);
} else {
echo "DNS解析時間: " . $info['namelookup_time'] . " 秒\n";
}
// 關閉 CURL 请求
curl_close($ch);
die;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment