我从前任继承的 Apache 服务器上的 php cURL 扩展不起作用。
我正在使用以下代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.linkedin.com/nhome/');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $fp);
$response = curl_exec($ch);
$errmsg = curl_error($ch);
$cInfo = curl_getinfo($ch);
curl_close($ch);
返回错误:
* name lookup timed out
* Couldn't resolve host 'www.linkedin.com'
* Closing connection #0
但是,如果我使用 IP 地址而不是 URL,它就可以正常工作:
* About to connect() to 54.171.54.110 port 80
* Trying 54.171.54.110... * connected
* Connected to 54.171.54.110 (54.171.54.110) port 80
我猜这是 DNS 问题?我应该如何开始解决问题?
答案1
感谢 ThoriumBR 的评论,推动了正确的方向。
/etc/resolv.conf 中列出的名称服务器不起作用,因此我用谷歌的公共名称服务器替换它:
nameserver 8.8.8.8
nameserver 8.8.4.4