PHP file_get_contents 抛出“无法打开流:HTTP 请求失败!”访问大型 xml 文件时 5-10 秒内
我正在尝试加载一个文件 ("http://feeds. artistdata.com/xml.shows/artist/AR-YX458DZO75EQACZ3/xml") 和 file_get_contents 但我5-10 秒内出现错误。 xml 文件在浏览器中加载良好,如果我使用它的较小版本(在上述 url 末尾添加“/future”),它可以使用 file_get_contents 加载良好。
脚本是:
$file = "http://feeds.artistdata.com/xml.shows/artist/AR-YX458DZO75EQACZ3/xml";
$data = file_get_contents($file);
出现两个错误之一,或者:
Warning: file_get_contents("http://feeds.artistdata.com/xml.shows/artist/AR-YX458DZO75EQACZ3/xml") [function.file-get-contents]: failed to open stream: HTTP request failed! in MY_PHP_SCRIPT.php on line 2
或者:
Warning: file_get_contents("http://feeds.artistdata.com/xml.shows/artist/AR-YX458DZO75EQACZ3/xml") [function.file-get-contents]: failed to open stream: Connection timed out in MY_PHP_SCRIPT.php on line 2
有什么想法吗?我尝试过使用 cURL 代替,但是当我这样做时,我只是得到“第 1 行错误”。该错误在不到 10 秒的时间内出现,所以我无法想象这是一个超时问题,因为这些默认值通常是 15 秒或 30 秒,具体取决于应用程序。
I'm trying to load a file ("http://feeds.artistdata.com/xml.shows/artist/AR-YX458DZO75EQACZ3/xml") with file_get_contents but I'm getting an error within 5-10 seconds. The xml file loads fine in a browser, and if I use a smaller version of it (adding "/future" on the end of the above url) it loads fine with file_get_contents.
The script is:
$file = "http://feeds.artistdata.com/xml.shows/artist/AR-YX458DZO75EQACZ3/xml";
$data = file_get_contents($file);
One of two errors show up, either:
Warning: file_get_contents("http://feeds.artistdata.com/xml.shows/artist/AR-YX458DZO75EQACZ3/xml") [function.file-get-contents]: failed to open stream: HTTP request failed! in MY_PHP_SCRIPT.php on line 2
Or:
Warning: file_get_contents("http://feeds.artistdata.com/xml.shows/artist/AR-YX458DZO75EQACZ3/xml") [function.file-get-contents]: failed to open stream: Connection timed out in MY_PHP_SCRIPT.php on line 2
Any ideas? I've tried using cURL instead, but when I do that I just get "Error on line 1". The error shows up in less then 10 seconds, so I can't imagine it's a timeout issue, since those defaults are generally 15 seconds or 30 seconds depending on the app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
//将此用于您的 xml feed 效果很好
$load = file_get_contents('http://artistdata.sonicbids.com/ari-herstand/shows/xml/');
打印_r($负载);
//use this for your xml feed works fine
$load = file_get_contents('http://artistdata.sonicbids.com/ari-herstand/shows/xml/');
print_r($load);
file_get_contents() 以字符串形式返回文件,从指定的偏移量开始最多 maxlen 个字节
E_WARNING如果 maxlength 小于零,或者 offset 超过流的长度,则会生成级别错误。
file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes
An E_WARNING level error is generated if either maxlength is less than zero, or if offset exceeds the length of the stream.