【发布时间】:2016-03-16 16:46:40
【问题描述】:
我正在通过 vagrant 配置的虚拟机虚拟机内运行本地 LAMP Web 服务器,该虚拟机位于公司代理后面。
我正在尝试使用php-curl 从网络服务器发出外部 HTTP 请求,但它们只是超时;但是通过 php-curl 请求本地地址可以正常工作。
片段:
$ch = curl_init();
$fp = fopen('/tmp/curl-debug.txt', 'w');
$options = array(
CURLOPT_URL => 'http://stackoverflow.com',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 15,
CURLOPT_MAXREDIRS => 10,
CURLOPT_VERBOSE => true,
CURLOPT_STDERR => $fp
);
curl_setopt_array( $ch, $options );
$response = curl_exec($ch);
curl_close($ch);
调试日志:
* Hostname was NOT found in DNS cache
* Trying 23.201.173.230...
* Connection timed out after 10001 milliseconds
* Closing connection 0
有用的信息:
- 我的操作系统:Windows 7
- 虚拟机操作系统:Ubuntu 14.04.4
- PHP v5.5.9-1
- Apache 2.4.7
- VM 的 private_network ip 为 192.168.33.10
- 值得一提的是,我支持一个公司代理,该虚拟机配置为与 AFAIK 完美配合。
如果我尝试从虚拟机的命令行运行 curl,一切都会按预期运行
例如:curl http://stackoverflow.com/ 返回 html。
nslookup 来自 VM 内部:
Server: 10.0.2.3
Address: 10.0.2.3#53
Non-authoritative answer:
Name: stackoverflow.com
Address: 104.16.35.249
Name: stackoverflow.com
Address: 104.16.34.249
Name: stackoverflow.com
Address: 104.16.37.249
Name: stackoverflow.com
Address: 104.16.33.249
Name: stackoverflow.com
Address: 104.16.36.249
我已经阅读了/etc/resolv.conf 可以在其中发挥作用,并确保用户组www-data 具有读取权限。我的 resolv.conf:
nameserver 10.0.2.3
search proxy.internal
我已尝试将名称服务器更改为 8.8.8.8 没有运气,并尝试将搜索更改为 proxy.internal 解析到的 ip。
我也尝试通过 php-curl 到达域解析到的 IP 以绕过 dns,但它仍然超时。
我没有想法,谷歌搜索结果!
【问题讨论】:
-
只是好奇,
LAMP中的L代表什么? -
Linux。我在虚拟机中运行 ubuntu (vagrant)
-
向我们展示您的代码。你有 FOLLOWLOCATION 设置吗?您是否尝试过 curl_getinfo() 来调试事务?
-
看看 CURLOPT_NOPROGRESS、CURLOPT_VERBOSE、CURLOPT_STDERR、CURLOPT_PROGRESSFUNCTION
-
也看看 curl_error
标签: php apache curl dns vagrant