在同一服务器上使用file_get_contents或curl进行url [英] Using file_get_contents or curl to url on same server
问题描述
我有一个PHP脚本,需要处理同一站点的RSS feed.具体来说,我将在首页上显示WordPress RSS feed中的最新博客.在我们的登台服务器上,它运行良好,但是在我们的实时(这是完全不同的,但LAMP)托管环境中,它无法正常工作.
I have a PHP script that needs to process the same site's RSS feed. Specifically, I'm displaying the most recent blogs from the WordPress RSS feed on the home page. On our staging server it worked fine but on our live (which is a completely different, but LAMP) hosting environment it's not working.
我可以在远程URL上运行 file_get_contents
或 curl
,但是当我尝试检索自己的RSS feed时,返回了一个404 not found页面.另一个奇怪的是,如果我尝试 file_get_contents(http://domain.com/test.txt)
,它将失败并显示404,但是如果我尝试 file_get_contents(http://www.domain.com/test.txt)
,我得到了测试文本文件的内容.所有这些都假设我正在从domain.com(而不是www.domain.com)运行脚本
I can run file_get_contents
or curl
on a remote url fine, but when I try to retrieve our own RSS feed, I am returned a 404 not found page. One other oddity, if I try file_get_contents(http://domain.com/test.txt)
it fails with a 404 but if I do file_get_contents(http://www.domain.com/test.txt)
I get the contents of the test text file. This is all assuming I'm running the script from domain.com (not www.domain.com)
我在这里设置了一个示例: http://bkwld.com/test.php
I've setup an example here: http://bkwld.com/test.php
推荐答案
好吧,我仍然不知道为什么这样做,但是我将通过feedburner运行feed并解析它来解决这个问题.RSS订阅.由于它位于远程域中,因此可以在我的测试中使用.不理想,但有.
Ok, I still don't know why the hell it's doing this, but I'm going to solve it by running my feed through feedburner and then parsing it's RSS feed. Because it's on a remote domain, it works in my tests. Not ideal, but w/e.
这篇关于在同一服务器上使用file_get_contents或curl进行url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!