英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论