PHP curl返回错误6是因为一个网站的问题。

huangapple go评论63阅读模式
英文:

Why does PHP curl returns error 6 for one website?

问题

I'm trying to access www.alberta.ca/ with PHP curl but it returns "Curl failed with error #6: Could not resolve host", although the website is online and returns a nice 200.

Here is my code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.alberta.ca/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);

I tried all the solutions I could find, for example adding the following options:

curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

But nothing works. Strangely, it works from my localhost, but not from my server.

英文:

I'm trying to access www.alberta.ca/ with PHP curl but it returns "Curl failed with error #6: Could not resolve host", although the website is online and returns a nice 200.

Here is my code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.alberta.ca/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);

I tried all the solutions I could find, for example adding the following options:

curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 2 );
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

But nothing works. Strangely, it works from my localhost, but not from my server.

答案1

得分: 1

问题出在我们的服务器配置上,而不是我们的代码。

遵循 @CBroe 的建议,我们只是更改了我们的DNS服务器,现在它可以正常工作。

英文:

The issue was on our server configuration, not our code.

Following @CBroe suggestion, we simply changed our DNS server and now it works.

huangapple
  • 本文由 发表于 2023年6月8日 18:34:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430968.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定