RSS script with cache function

The native function SimpleXML in PHP5 is a great functionality to parse a XML feeds as HTML show content on your website. Maybe you like to show your last blog posts on your company’s website? If your website has some bigger traffic, you should think about to cache the RSS/XML file to lower the server load on the host where your RSS feed is hosted. This small PHP snippet will check if there is already a fresh cached version and if not a new feed is requested with PHP file functions. In that case a cache version for the new XML file is stored on the website’s host. With this function the XML is stored unchanged, why? The XML has already a data structure which we use for later purposes. Using simpleXML, the XML is converted into an object and this object is used together with a loop to show some content in your HTML. In our example the RSS feed from our WordPress weblog is parsed to show the latest posts on our website.

Leave a Reply

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