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

时间:2014-11-10 20:16:04

标签: php

如果我放入我的php文件:

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

如果我在example.com上运行此脚本,该页面最终会超时。如果我在不同的服务器上运行相同的脚本,它会立即正确加载。我检查过,phpinfo()中的allow_url_fopen为'On'。任何想法可能是什么?提前谢谢。

2 个答案:

答案 0 :(得分:0)

使用this class

从URL获取DOM

喜欢

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

答案 1 :(得分:0)

使用网络标签中的chrome / firebug检查网页。 看看你发送的标题。

使用相同的标题创建一个新的file_get_contents。

See here how to send headers along with file_get_contents

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