php - curl namelookup_time 为 10 秒

标签 php curl

在 PHP 中对纯文本网页 (http://whatismyip.org/) 执行基本 curl 请求时,响应时间超过 10 秒。

查看来自 curl 的信息后,告诉我 namelookup_time 是 10 秒。从命令行(终端)执行 curl 时,我可以看到完全相同的结果。

为什么名称查找需要这么长时间,根据我的阅读,很可能与托管 PHP 文件的服务器/我的计算机有关。


这是我的代码:

$ch = curl_init();  
curl_setopt( $ch, CURLOPT_URL, "whatismyip.org");
curl_exec( $ch );

$ci = curl_getinfo($ch);
print_r($ci);

这是信息:

[url] => HTTP://whatismyip.org 
[content_type] => text/plain 
[http_code] => 200 
[header_size] => 45 
[request_size] => 53 
[filetime] => -1 
[ssl_verify_result] => 0 
[redirect_count] => 0 
[total_time] => 10.549943 
[namelookup_time] => 10.100938 
[connect_time] => 10.300077 
[pretransfer_time] => 10.300079 
[size_upload] => 0 
[size_download] => 14 
[speed_download] => 1 
[speed_upload] => 0 
[download_content_length] => -1 
[upload_content_length] => 0 
[starttransfer_time] => 10.549919 
[redirect_time] => 0 
[certinfo] => Array ( )

最佳答案

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

帮我解决了这个问题。 IPV6 有一个不明显的错误。

关于php - curl namelookup_time 为 10 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8712167/

相关文章:

php - 使用 PHP IMAP 打开电子邮件

javascript - 使用 XMLHTTP JavaScript 通过 cURL PHP 接收参数

elasticsearch - 内容类型标题不支持错误消息

javascript - 在 PHP 中向随机用户显示 html 内容

java - 如何在通过 HTTP GET 获取文件后直接通过 HTTP PUT 发布文件?

curl - 使用备份插件从命令行触发 Jenkins 备份

php - 如果可以将参数传递给 codeigniter 中的 curl?

找不到 php.ini 文件?

php - 如何在一个 HTTP 请求中提供多种字体?

php - 传递给 Controller ​​的对象数组, View 并将它们作为列表显示在 View 中