My almost dynamic static HTML PHP RSS system

I am no real PHP developer – the most I’ve done with it is to produce some stuff that Flash communicates with in order to provide extra functionality for Flash content. Today I decided that I wanted to generate an RSS feed for a static news page that I have running on an intranet site. What I was able to pull off in a small amount of time is pretty cool (I think anyway).

What I Did
I have a PHP class that generates an RSS file as read by the browser. I have that static news page that I’d like to create a feed for – but it’s not using a database & thus there is no event that generates the RSS for updating the XML file on the box. One adds HTML to the news page and then a mechanism is required to automate the XML file.

What I’ve done is author a PHP file that loads my news page and parses it via the DOM. An unordered list to be exact. It pulls out parts via tags within it and in a loop builds an array of content. It then can either serve as the RSS itself or write the XML to the box. I’ve found serving as the feed itself seems to cache itself somehow & even thought the content has been updated, Safari (at least) still sees the old RSS content. I’ve tried to limit the caching, but using a regular XML file seems to do the trick.  I feed the content into an instance of the PHP class and out pours a valid feed. Written to the box and referenced in the HEAD of the pages in the intranet site.

Getting Things Dynamic (Sorta)
So, everything is fine and dandy, except one would need to load that PHP file in order to produce the XML file. Not very dynamic is it? To get around this huge limitation I created a cron job on the box. Monday through Friday from 8AM to 5PM, every 30 minutes, the cron job loads that PHP file, thus automatically creating a new XML file so that readers can notify whomever is subscribed to the new content. It’s not efficient because if the feed content isn’t changing it’s still producing the RSS file. But since it’s on a local box, it should be okay.

Not bad after having never parsed DOM objects in PHP, never creating a valid feed from PHP, never writing a file with PHP on the fly, and never creating a cron job until today. To be honest, I used Cronixx to create the cron job for me (it’s an OS X GUI command-line tool).

It’s Fun To Learn New Things
To be honest, if no one ever subscribes to the intranet feed that’s okay with me. I was able to learn some more PHP to solve a task that I gave myself. It’s working well so far.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × = six

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>