Welcome to WebmasterWorld Guest from 54.226.60.235

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Error Capture RSS Feed using PHP

     

pemba76

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

5+ Year Member



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.

enigma1

7:11 pm on Sep 19, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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
}

pemba76

4:36 am on Sep 20, 2010 (gmt 0)

5+ Year Member



How do i cache the result ? Do you mean to save it in a Database and retrieve ?

enigma1

8:30 am on Sep 20, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



yes or in a file.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month