There are many situations where you might want to display up-to-date information
on your website. I will use the process of displaying the latest headlines from Slashdot.org
as an example here.
Getting the headlines
The file http://slashdot.org/slashdot.xml
contains the current slashdot headlines for people to use on their websites. You could
just load the data from this file every time someone visits your page. However, Slashdot requests
that you only access the file once every 30 minutes or more (to reduce the load on their server).
This means we will need a better strategy for making sure we have up-to-date headlines.
You could use cron to perform the update once every 30 minutes but for various reasons this
might not be possible. My approach is to write a PHP script that does the following when a user loads
the page with the dynamic content:
1. Check whether a local (i.e. on my webserver) copy of slashdot.xml has been updated
within a predefined time period (more than 30 mins in this case).
2. If it has not been updated recently enough then download the current one from
slashdot.org.
3. Display the data from the local copy of slashdot.xml.