是否可以忽略PHP cURL请求中的DNS

时间:2015-07-01 11:33:50

标签: php curl dns

我正在尝试使用cURL从服务器1访问服务器2上的API。 从开始到结束大约需要15秒才能从服务器2返回数据。 API接受GET信息,并在地址栏中输入URL和参数即时返回数据。因此,我很高兴API代码具有高性能,并且问题在于cURL请求/网络。

使用curl_getinfo()方法,我看到以下内容:

[url] => http://[targetURL]
[content_type] => application/json
[http_code] => 200
[header_size] => 423
[request_size] => 135
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 15.137161
[namelookup_time] => 15.039278
[connect_time] => 15.057024
[pretransfer_time] => 15.057177
[size_upload] => 0
[size_download] => 849
[speed_download] => 56
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 15.131828
[redirect_time] => 0
[certinfo] => Array
    (
    )
[primary_ip] => xxxx
[primary_port] => 80
[local_ip] => yyyy
[local_port] => 24995
[redirect_url] => 

让我困扰的是namelookup_time。 这是尝试使用DNS来解析我指定的域吗? 是否可以指定IP地址? 如果是这样,我的主机会为我的包分配一个IP。有没有人有任何为子域分配端口号或专用IP的经验? 我的主人是1& 1,包裹是Unlimited Plus。

非常感谢任何智慧的话语。 标记

1 个答案:

答案 0 :(得分:0)

如果您要对同一个名称进行重复查询,则可以使用IP地址或将条目添加到运行该脚本的计算机的主机文件中。除非你专门在脚本中调用DNS查找,否则应该将查找时间减少到几乎为零。