Using Cron with LWP::Simple and XML::RSS to retrieve news feeds
Originally published on March 24, 2003 when the war in Iraq was heating up and I found direct links to popular RSS news feeds were effecting the speed in which pages loaded. I’m reposting this article for reasons that will become obvious later this week. Until then, enjoy this “Spidering Hack!-)”
Adding some syndicated news feeds is a nice way of adding some compelling content to your site. The problem is that sometimes the news feed gets overrun during heavy news days, go offline and/or suffers a host of other connectivity issues that make YOUR site load slow because the software holds your user hostage while the feed retrieval portion of the application has to wait to timeout. You see this alot with PHPNuke and PostNuke sites.
A simple way around this problem is to use a program that periodically retreives the feed and slices-n-dices it into an easy to include file on your host. Doing this achieves five goals
- user page loads are not penalized when feeds go down
- failures to connect do not harm the existing include file
- multiple attempts to read the feed to not penalize user
- feed can be mirrored for local/private use
- content can be formatted to taste
Below is a little program I wrote Thursday to grab news feeds from an AP Wire I found via Scripting.com for inclusion on blogs4God. Using the following CRONTAB syntax, the program is executed every 30 minutes.
The nice thing about this approach is that this particular feed does “get busy” from time to time and at one point on Friday went offline. My users did not notice because in most cases, I was able to get by the “busy signal” on the 2nd or 3rd attempt out of 10. In the case where the feed site went offline, my users merely viewed and older include file without interruption or delay.
Anyway, since I haven’t posted anything worthwhile in the past few days, I figured this was a good pennance:
Of course, now if the impatient news media and certain ‘Ophrahized’ peacenicks would quit interpreting combat casualties as a total military failure … we’d have something worth reading — but I digress.










