【发布时间】:2015-06-12 05:18:27
【问题描述】:
我的代码:
<?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>
这会是个问题吗?
【问题讨论】:
-
您是否有 GUI,如果有,您是否尝试过在 Web 浏览器中访问 URL?如果您有 CLI 访问权限并拥有 Wget,您可以尝试使用 Wget 执行相同的请求并告诉我结果。
-
连接超时通常意味着防火墙丢弃了请求。服务器操作系统是什么,你能
telnet从外部的机器上连接到这台机器的80端口吗? -
通过在标题stackoverflow.com/questions/10524748/… 中添加代理来尝试此操作
-
如果你的意思是像
"User-Agent: ".$_SERVER["HTTP_USER_AGENT"]."\r\n"这样也不会起作用。
标签: php stream file-get-contents