Uli's Web Site |
|
blog |
Now supporting if-modified-since !
For quite a while, I've been meaning to add a full-text RSS feed to my site. There's one obstacle, though: Since I instated it, the RSS feed was the top bandwidth hog on my site. A full-text feed would mean that, every time someone's RSS reader checks whether I've written something new on this site, it would download all articles. I simply didn't want to take that hit, especially in light of the upcoming new version of the Moose, which tends to eat bandwidth like there's no tomorrow. But then, in the feature description of one blogging engine, I read that HTTP supports just sending back a "this page is unchanged" reply. So, I added that. Read on to learn how: $cond = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : 0; if( $cond && ($_SERVER['REQUEST_METHOD'] == 'GET') && (strtotime( $cond ) >= $aw_newestdate) ) { header( "HTTP/1.0 304 Not Modified" ); exit; } header( "Last-Modified: " . gmdate( "D, d M Y H:i:s", $aw_newestdate ) . " GMT" ); // echo page contents here. Where $aw_newestdate is a variable containing a Unix timestamp indicating when the page was last changed. Now, I haven't had much time to test this, and some browsers simply don't send conditional requests, but if everything works as intended, I'll notice a drop in bandwidth consumption in next month's server statistics. And if that drop is large enough, I may just get to give you that full-text RSS feed we all want so much... |
Created: 2005-07-27 @810 Last change: 2005-07-27 @861 | Home | Admin | Edit © Copyright 2003-2024 by M. Uli Kusterer, all rights reserved. |