Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php curl\u getinfo不返回任何内容。加载需要30秒_Php_Redirect_Curl - Fatal编程技术网

Php curl\u getinfo不返回任何内容。加载需要30秒

Php curl\u getinfo不返回任何内容。加载需要30秒,php,redirect,curl,Php,Redirect,Curl,最近,一段简单的代码停止了工作。 代码基本上是获取页面源代码,我使用的是文件“get”contents('www.urlofpageiwanttoload.com'); 由于某些原因,现在加载并返回false需要花费很长时间 所以我决定使用curl来获取更多调试信息 所以我提出如下要求 function curl_get_file_contents($URL) { $c = curl_init(); curl_setopt($c, CURLOPT_HEADER, true);

最近,一段简单的代码停止了工作。 代码基本上是获取页面源代码,我使用的是文件“get”contents('www.urlofpageiwanttoload.com'); 由于某些原因,现在加载并返回false需要花费很长时间

所以我决定使用curl来获取更多调试信息

所以我提出如下要求

function curl_get_file_contents($URL)
{
    $c = curl_init();
    curl_setopt($c, CURLOPT_HEADER, true);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($c, CURLOPT_URL, $URL);
    $contents = curl_exec($c);
    print_r(curl_getinfo($c));
    print_r(curl_error($c));
    curl_close($c);

    if ($contents) return $contents;
    else return FALSE;
}
现在这也需要30秒来加载。 然后curl_getinfo()将以下内容打印给我

Array
(
 [url] => HTTP://www.urlOfThePageIwantToLoad.com/
 [content_type] => 
 [http_code] => 0
 [header_size] => 0
 [request_size] => 0
 [filetime] => -1
 [ssl_verify_result] => 0
 [redirect_count] => 0
 [total_time] => 20.172
 [namelookup_time] => 0.016
 [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
     (
     )
 [redirect_url] => 
)
curl\u error()
给了我这个

未能连接到www.urlofpagewanttoload.com:80;无错误

发生了什么事


提前感谢您的帮助。

可能是网络错误。你不允许这样从你的服务器上进行访问,防火墙是用来阻止它的,等等等等,但问题是,当我使用google.com作为URL时,启动一个shell,然后尝试
traceroute www.urloffegeiwantoload.com
,看看这个主机是否可以访问。即使那样,也许你这边的一切都很好。可能该主机已将您的IP列入黑名单。请从运行您的脚本的计算机上尝试
telnet www.urlopagewanttoload.com 80
,查看您是否可以访问该站点。我喜欢ping/traceroute/telnet建议。也可以增加你的超时时间,看看它是否最终会响应
CURLOPT\u连接超时
CURLOPT\u超时