Php 旋度为';不解析主机

Php 旋度为';不解析主机,php,curl,Php,Curl,我在新的专用服务器上,在curl连接上出错 我试过了 $_h = curl_init(); curl_setopt($_h, CURLOPT_HEADER, 1); curl_setopt($_h, CURLOPT_RETURNTRANSFER, 1); curl_setopt($_h, CURLOPT_HTTPGET, 1); curl_setopt($_h, CURLOPT_URL, 'http://api.beatport.com/catalog/labels/detail?id=

我在新的专用服务器上,在curl连接上出错

我试过了

$_h = curl_init(); 
curl_setopt($_h, CURLOPT_HEADER, 1); 
curl_setopt($_h, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($_h, CURLOPT_HTTPGET, 1); 
curl_setopt($_h, CURLOPT_URL, 'http://api.beatport.com/catalog/labels/detail?id=14248&format=json&v=1.0' ); 
curl_setopt($_h, CURLOPT_DNS_USE_GLOBAL_CACHE, false ); 
curl_setopt($_h, CURLOPT_DNS_CACHE_TIMEOUT, 2 ); 
var_dump(curl_exec($_h)); 
var_dump(curl_getinfo($_h)); 
var_dump(curl_error($_h)); 
我得到了

bool(false) array(21) { ["url"]=> string(72) "http://api.beatport.com/catalog/labels/detail?id=14248&format=json&v=1.0" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["certinfo"]=> array(0) { } } string(40) "Couldn't resolve host 'api.beatport.com'"
这可能是DNS问题

已解决:


我打开了/etc/hosts并添加了我想通过curl检索的网站的ip,它成功了

您的代码正常。这实际上是专用服务器上的DNS配置问题。检查您的托管服务是否允许传出curl连接。

我在代码点火器代码中遇到了相同的问题。我的服务器在DigitalOcean

我的解决方案是重新启动服务器。

服务apache2重新启动


非常感谢

可能是防火墙问题。是否允许您的服务器进行传出连接?您是否尝试ping域?可能是出站代理?我以前在出站安全主机上看到过这种情况。它连接smtp.com进行smtp中继没有任何问题,如何检查其AllowedDefinity是否确实是DNS问题…您不必修改本地主机文件。我建议删除该条目并找出查找失败的原因。如果主机服务不允许,是否有任何修复方法或什么都不做?当命令行中的nslookup工作正常时,Curl无法解析主机。我尝试了apachectl重新启动-没有工作。停止apache并重新启动它-这就解决了它。我猜服务apache2 restart与apachectl restart不同在Mac上重启apache可以这样做
sudo apachectl restart