Software Engineer

php rss parser

· by jsnby · Read in about 2 min · (234 Words)
Computers

The other day I was hacking together a quick app to monitor some rss feeds and stuff some data into a MySQL database. One thing I really hate is writing XML parsers. I can do it easily, I just find it tedious. Couple that with my lack of knowledge of the RSS format and I wasn’t looking forward to parsing the XML at all.

A quick google search turned up SimplePie, an RSS feed parser written in PHP. The documentation and examples were straightforward. SimplePie has a very clean API.

I like how it caches the feeds and only downloads new feeds if necessary thus conserving bandwidth. I don’t particularly like that by default it caches files on disk (meaning that if you’re using SimplePie from the browser, that Apache needs permissions to write to disk), but it appears that they’re adding MySQL caching support…I couldn’t tell if the MySQL caching was officially supported in v1.2 or if it was still considered experimental, so I stuck with caching to flat files on disk. In my case, the app that’s doing the parsing of the feeds is running out of a cron job, so I didn’t have to give the Apache user permission to write to disk.

Anyhow, using SimplePie made it a breeze for me to finish building the rest of my app. I highly recommend it if you need a PHP RSS parser.