KBD

Keith Devens .com

Thursday, March 18, 2010 Flag waving
All warfare is based on deception. – Sun Tzu (The Art of War (I.18))

Archive: May 05, 2004

← May 03, 2004May 06, 2004 →

Daily link icon Wednesday, May 5, 2004

Cron question

Is there a way to run a cron every 90 minutes? If my cron line is something like:

*/90 * * * *

It runs every 60 minutes. It seems like the minute counter won't let it go above 60. But then how can I run something every hour and a half (or two hours and a half), or every 72 minutes or something?

Caching

I changed the caching on my entire site, so, this is here so I can leave comments to make sure everything's hunky dory.

Conditional get

In the spirit of Simon's, I created my own conditional get function. My RSS feed finally does conditional get Smiley

<?php
function httpConditionalGet($timestamp$is_timestamp true){
    if(
$is_timestamp$last_modified gmdate('r'$timestamp);
    if((isset(
$_SERVER['HTTP_IF_NONE_MATCH']) and $_SERVER['HTTP_IF_NONE_MATCH'] == $timestamp) or
        (
$is_timestamp and
        isset(
$_SERVER['HTTP_IF_MODIFIED_SINCE']) and
        
$_SERVER['HTTP_IF_MODIFIED_SINCE'] == $last_modified)
    ){
        
header('HTTP/1.1 304 Not Modified');
        exit;
    }
    if(
$is_timestampheader("Last-modified: $last_modified");
    
header('ETag: '.($is_timestamp $timestamp md5($timestamp)));
}
?>

So, you can pass it a timestamp and it'll use Last-modified headers, but if you explicitly tell it it's not a timestamp then it won't and will just use an ETag instead.

Update (5/7): Note that this code is kind of broken. It was just a quick hack that worked for me, but I didn't test it well because I was (and still am) in the middle of finals. Once I get a chance I'll revise it and fix what's broken. Thanks to Bob Congdon for pointing me to what I did wrong. I explain some of the things in the comments on his post about this.

Update (12/11): I figured I'd post the updated, correct version of this code:

<?php
function httpConditionalGet($thing$is_timestamp true){
    
#thing can be either a timestamp or anything else you want to serve as an etag
    #if it's not a timestamp, it's the caller's responsibility to md5 it or whatever
    
if($is_timestampheader('Last-modified: '.($lm gmdate('r'$thing)));
    
header('ETag: "'.$thing.'"');
    
$client_etag = isset($_SERVER['HTTP_IF_NONE_MATCH'])     ? $_SERVER['HTTP_IF_NONE_MATCH']     : NULL;
    
$client_lm   = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : NULL;

    if((
$client_etag and $client_etag == '"'.$thing.'"'#etag
       
or
       (
$is_timestamp and $client_lm and ($client_lm == $lm or $thing == strtotime($client_lm))) #last-modified
    
header('HTTP/1.1 304 Not Modified') and exit;
}
?>

It looks much better when it's not word-wrapped.

← May 03, 2004May 06, 2004 →
March 2010
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 2 posts

Recent comments XML

I hate ASP.NET

I hate ASP... I was doing wonders​with PHP, then suddenly one of my​clients...

Johnies: Mar 17, 6:14am

Quantum physics and free will

I knew you were going to say that....

Tom Massey: Mar 15, 9:26pm

Generated in about 0.044s.

(Used 7 db queries)