Welcome to WebmasterWorld Guest from 107.20.75.63

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Error Capture RSS Feed using PHP

     
8:26 am on Sep 13, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:June 15, 2006
posts: 62
votes: 0


I access a RSS feed and the content is displayed in my website using PHP. There are times when there is no result from the RSS feed. How do i capture this so that i can display data from another source when the RSS feed fails.

I would like to capture the following when i access the RSS Feed :
1> Blank Result / No Result (Server us Up and running)
2> Server Response Very Slow or Server Down
3> Errors (Server us Up and running)

Please guide.
7:11 pm on Sept 19, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Apr 30, 2007
posts:1394
votes: 0


You connect to another site in order to retrieve the feed. If you are using say fsockopen you can setup a timeout and the function returns accepts a couple of parameters for the error codes

eg:
$fp=@fsockopen('tcp://'.$domain, 80, $errno, $errstr, 5);

So you can determine if the function failed or not and what the error is. Also you could cache the results daily instead of getting the feed with each request.

If the fp is false meaning the call failed then you could try another page to get your feed from. The 5th parameter is the timeout in secs. You could set it up so the code won't wait too long for a connection.

if( !$fp ) {
// Fetch alternative feed
}
4:36 am on Sept 20, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:June 15, 2006
posts: 62
votes: 0


How do i cache the result ? Do you mean to save it in a Database and retrieve ?
8:30 am on Sept 20, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Apr 30, 2007
posts:1394
votes: 0


yes or in a file.