使用 php 制作 xml feed 的本地副本时遇到问题
我正在尝试保存 xml 文件的本地副本,然后使用简单的 xml 打开它,但我遇到了一些错误..这是我的代码:
$feedURL = "https://gdata.youtube.com/feeds/api/users/manitobachildhealth/favorites";
//$xml = file_get_contents("$feedURL");
$xml = file_get_contents($feedURL);
file_put_contents("video.xml", $xml);
// read feed into SimpleXML object
//$sxml = simplexml_load_file($feedURL);
$sxml = simplexml_load_file('video.xml');
我收到的错误如下:
Warning: file_get_contents(https://gdata.youtube.com/feeds/api/users/manitobachildhealth/favorites) [function.file-get-contents]: failed to open stream: Result too large in D:\wamp\www\videos2.php on line 48
我不确定为什么结果会太大,它只返回 6kb 的 xml。我做错了什么?
更新: 这是使用 WAMP 服务器在 Windows 平台上运行的 - 并不理想,但我坚持使用它。
更新2: 我尝试使用curl 和fwrite 来实现类似的结果,如下所示,但它不会将xml 文件写入本地服务器。但它不会给我任何错误。
更新3: 这显然是托管环境的一个非常具体的问题,但我不确定从哪里开始寻找问题。使用curl 在基于Linux 的开发服务器上运行良好,但在基于Windows 的生产服务器上会导致问题。如果您能提供解决此问题的额外帮助,我们将不胜感激!
I'm trying to save a local copy of an xml file, and then open it with simple xml, but i'm getting some errors.. here's my code:
$feedURL = "https://gdata.youtube.com/feeds/api/users/manitobachildhealth/favorites";
//$xml = file_get_contents("$feedURL");
$xml = file_get_contents($feedURL);
file_put_contents("video.xml", $xml);
// read feed into SimpleXML object
//$sxml = simplexml_load_file($feedURL);
$sxml = simplexml_load_file('video.xml');
The error i'm getting is as follows:
Warning: file_get_contents(https://gdata.youtube.com/feeds/api/users/manitobachildhealth/favorites) [function.file-get-contents]: failed to open stream: Result too large in D:\wamp\www\videos2.php on line 48
I'm not sure why it would be too large of a result, it only returns 6kb of xml. what am i doing wrong?
Update:
This is running on a windows platform using WAMP server - not ideal, but i'm stuck with it.
Update 2:
I've tried using curl and fwrite to achieve a similar result, as suggested below, but it won't write the xml file to the local server. It doesn't give me any errors though.
update 3:
This is obviously a very specific problem with the hosting environment, but I'm not sure where to start looking for the problem. Using curl works great on a linux-based dev server, but is causing problems on this windows-based production server. An extra help in troubleshooting this issue would be most appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题的正确答案:
您可能遇到与此问题相同的问题:CURL 和 HTTPS,“无法解析主机”(DNS 问题)
其他详细信息:
您可以使用 SimpleXML 加载和保存
我已经测试过的 xml 数据上面的代码在 WAMP 服务器中,它工作正常。
更新:
如果上面返回错误消息“[simplexmlelement.--construct]:I/O警告:无法加载外部实体......”,则可能是您的服务器不允许包含外部数据或php文件/脚本不允许拥有正确的许可。
请尝试以下操作:
1.回显xml文件的内容。
如果您设法检索 xml 内容并将其打印到浏览器,则您的服务器允许包含外部内容,并且很可能是文件权限问题。确保文件/脚本有权创建 xml 文件。
如果上述方法仍然不起作用,请尝试使用 cURL。
Correct answer for the question:
It is possible you are having the same problem as of this question: CURL and HTTPS, "Cannot resolve host" (DNS-Issue)
Other Details:
You can use SimpleXML to load and save the xml data
I have tested the code above in a WAMP server and it works fine.
Update:
If the above returns error message "[simplexmlelement.--construct]: I/O warning : failed to load external entity ...." It's possible that your server does not allow to include external data or the php file/script does not have the right permission.
Try the following:
1. echo the content of the xml file.
If you managed to retrieved the xml content and print it to the browser, then your server is allowing to include external content and most likely the problem with the file permission. Make sure file/script have the right to create xml file.
If the above still does not work try using cURL.
您是否尝试过使用curl和fwrite来获取内容并将它们写入本地文件?
Have you tried using curl and fwrite to get the contents and write them to a local file?