作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在 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 中对纯文本网页 (http://whatismyip.org/) 执行基本 curl 请求时,响应时间超过 10 秒。 查看来自 curl 的信息后,告诉我 namelookup_time
编辑:找到部分原因 - 见底部。 我正在从 php 执行标准的 curl 调用。但是,在名称解析期间似乎出现了挂断。在我的 OSX 机器上,namelookup_time 对于同一子网的这个查询和其他
我是一名优秀的程序员,十分优秀!