TaciturnMon 21 May 2007
When it came to writing an RSS feed for my blog I knew that it was likely to be hit up fairly often by feed readers and indexers. Far more often than I'd be posting, anyway. So I knew that dynamically generating the page on every access would be ridiculously inefficient. For an indication of how loaded my web server is, its current memory use is 58 MB resident, 98 MB swapped. It is not a highly resourced machine. So I set up a directory that the web server had write access to, wrote a PHP-CLI script to do all the usual MySQL hocus-pocus to get back the top 10 posts and render them as RSS, and hooked it into the posting interface. The RSS feed is only written to a file when a post is made or edited, and thereafter Apache just serves up the pre-rendered ~15 kB RSS file. Way more efficient. Actually it turns out that feed readers usually make a GET request with the If-Modified-Since header, which is really good for reducing server load. If the feed hasn't changed, the server sends an HTTP 304 Not Modified response with no body. All that requires is a stat() on the file to see if its mtime has changed. Another benefit is that if some part of the script fails, for instance the database is temporarily unavailable while upgrading the database software, the page is still accessible. The script can fail in whatever way it likes, and it won't spew PHP messages into the output file or produce a half-complete and totally invalid XML file. The page is rendered to a temporary file and then (atomically) renamed to the destination filename when it's ready. As a result of all this, it doesn't particularly bother me that some RSS library called Rome is hitting up the RSS feed every 7 minutes despite the feed's TTL of 1 day. I'd prefer it didn't, but at least I can handle it.
Also available in
|
Comments
There are no comments on this entry.