gpt4 book ai didi

php - curl namelookup_time 为 10 秒

转载 作者:可可西里 更新时间:2023-11-01 13:40:27 24 4
gpt4 key购买 nike

在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com