Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP RSS caching

Tags:

php

caching

rss

I was looking for a solution on caching RSS feeds in PHP. I was planning to do the parsing with Magpie RSS parser (http://magpierss.sourceforge.net/). But then how could I go about caching feeds (in case sometimes feed provider won't let me read the same feed, etc.)?

Regards.

like image 911
azec-pdx Avatar asked Aug 08 '26 06:08

azec-pdx


2 Answers

  • You fetch the feed. Save the results to a database or file (serialize()).
  • When it is time to fetch the feed again,
  • Check if the file exists, if not create and update
  • If the file exists, check the the timestamp of the db or file.
  • if it is older than your threshold (say 20 secondsm) then you refetch, otherwise you just return the cached feed.
  • If you can't fetch the feed for whatever reason, you return the cached version up to a timeout period (say 20 minutes)

Voila caching.

like image 77
Byron Whitlock Avatar answered Aug 10 '26 23:08

Byron Whitlock


fetch a list of feeds say, every hour using wget.

Write them into a folder called /cache

Repeat.

This would work fine as long as a) hourly is good enough b) hourly is good enough for all feeds and c) you have access to cron

Gotta wonder why you are fetching and serving the feeds unless you are doing some post-fetch analysis on them though.

like image 34
Cups Avatar answered Aug 10 '26 23:08

Cups