问题描述
此函数在localhost上运行,但不在远程服务器上。
This function works on localhost, but not on my remote server.
我向服务器主人询问了这一点,并告诉我PHP CURL已启用,工作良好。
I inquired the server master about this, and it told me PHP CURL is enabled and things should work fine.
这里是代码:
我测试的$ url是:
the $url that I am testing with is:
$url = "http://bus.go.kr/getSubway_6.jsp?statnId=1003000323&subwayId=1003"
以下是函数:
function file_get_html_using_cURL($url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 2 );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, faslse);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
if(curl_errno($ch)){
echo 'Curl error: ' . curl_error($ch);
echo "\n--------------------\n";
print_r(curl_getinfo($ch));
echo "\n--------------------\n";
}
$output = str_get_html($output); // <-- Important line to convert string into object!
curl_close($ch);
return $output;
}
这是网站页面上的返回:
And this is what returns on the site page:
Curl error: Couldn't resolve host 'bus.go.kr'
--------------------
Array
(
[url] => http://bus.go.kr/getSubway_6.jsp?statnId=1003000323&subwayId=1003
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[certinfo] => Array
(
)
)
--------------------
我没有线索为什么这在远程服务器上不起作用。
I have no clue why this isn't working on the remote server.
我该怎么办?
推荐答案
curl
已启用,并在您的情况下完美。不幸的是,它运行的服务器不能解析名称 bus.go.kr
。在此上下文中解析意味着查找名称已知的Internet主机的IP地址。
curl
is enabled and works perfectly in your case. Unfortunately, the server where it runs cannot resolve the name bus.go.kr
. Resolving in this context means finding the IP address of an Internet host whose name is known.
可能有很多来源的问题。如果它是永久的,那么服务器可能配置错误。如果是暂时的,那么这可能是连接问题。
There can be many sources for the problem. If it's permanent then the server is probably misconfigured. If it's temporary then it's probably a connectivity issue.
您可以使用不同的网址进行更多检查,,看看你得到了什么结果。如果你不能达到任何一个,那么这是一个配置问题。
You can do more checks with different URLs, http://www.google.com for example, and see what results you get. If you cannot reach any of them then it's a configuration problem.
这篇关于PHP CURL curl_exec返回“无法解析主机”www。〜.com“。 CURL是否启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!