views:

1072

answers:

5

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.

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)

I've setup an example here: http://bkwld.com/test.php

+1  A: 

I had a very similar problem - you might try using 127.0.0.1 instead of your own domain name (assuming your apache setup doesn't prevent you doing that). Something to do with domain resolution I believe, quirk of the api.

Kazar
This would totally fail if the site is on a VirtualHost.
grawity
Yeah, I am unfortunately.
weotch
Do you know that your virtualhost is setup to alias www.domain.com and domain.com to each other?
Kazar
Yeah: ServerName bkwld.com:80ServerAlias www.bkwld.comUseCanonicalName OffDocumentRoot /var/www/vhosts/bkwld.com/site/htdocs... etc
weotch
A: 

Indeed, odd. How will you parse the file? You can maybe load it into SimpleXML directly;

$xml = simplexml_load_file("http://domain.com/blog/feed/index.php");
/* Use Simple XML to parse the RSS feed */

I realize this approach does not solve your problem, you only use another approach - but maybe it's enough for you.

Björn
Yeah, I was using the Zend Framework Zend_Feed_Rss() before, and that failed. Which is when I tried to get down to the source by using file_get_contents and CURL
weotch
+1  A: 

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.

weotch
+1  A: 

Hi,

I just had this similar issue. The DNS is the problem, it is not resolving your domain name. You should use the IP instead of the domain in your scripts.

You can ping your domain in cmd and use that IP.

Fernando
A: 

by the way, whats the point for a staging enviroment if it has a totally different config then the live env ? You should make it as equal as possible.

BarthQuay
I principle I agree. In our case, the hosting provider we use for staging is much cheaper than the live server and we use it to stage a number of our sites. It also has some control panel tools that make it nice as a staging server.
weotch