我的代码:
<?php
$url = "http://www.myurl.com/";
/*$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: ".$_SERVER['HTTP_USER_AGENT']
)
);
$context = stream_context_create($opts);*/
$content = file_get_contents($url);
echo $content;
?>我收到以下错误:
Warning: file_get_contents(http://www.myurl.com/) [function.file-get-contents]: failed to open stream: Connection timed out in /home/content/myurl/contents.php on line 10当我创建或不创建流上下文时,代码将不会为我工作。有趣的是,它可以在我尝试过的任何其他网站上工作,除了我自己的网站。
PS:无论我是否使用"http“或"www”,这都无关紧要。
PSPS: allow_url_fopen亮起
PSPSPS:我已经在.htaccess中设置了以下内容:
<filesMatch "\\.(html|htm|php)$">
Header set Cache-Control "max-age=1, private, must-revalidate"
</filesMatch>这会是一个问题吗?
发布于 2015-04-07 22:50:26
你试过使用curl吗?
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = 'http://www.myurl.com/';
$contents = curl($url);发布于 2015-04-07 22:51:32
请尝试将最大执行时间设置为较大的周期,可能已将其设置为较低的值。Ini_set(‘最大执行时间’,60);//1分钟
发布于 2015-04-07 22:53:27
您的服务器应具有防火墙,以限制您连接到外部资源。所以检查一下你的防火墙。
https://stackoverflow.com/questions/29494490
复制相似问题