file_get_contents在和目标相同的服务器上运行时超时


file_get_contents on times out when run on same server as target

如果我把放在我的php文件中

echo file_get_contents("http://www.example.com/myPage.php");

如果我在example.com上运行这个脚本,页面最终会超时。如果我在不同的服务器上运行相同的脚本,它会立即正确加载。我检查了phpinfo()中的allow_url_fopen是否为"On"。有什么想法吗?提前谢谢。

使用此类

用于从URL 获取DOM

$html = file_get_html("http://example.com");
echo $html;

在网络选项卡中使用chrome/firebug检查网页。看看你在发送什么邮件头。

制作一个具有相同标头的新文件_get_contents。

请参阅此处如何将标头与file_get_contents 一起发送

这就像实际打开网站一样,因此应该可以正常工作。