KBD

Keith Devens .com

Saturday, October 11, 2008 Flag waving
Philosophy: the finding of bad reasons for what one believes by instinct. – Brave New World (paraphrased)

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 →
October 2008
SunMonTueWedThuFriSat
 1234
567891011
12131415161718
19202122232425
262728293031 



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

Recent comments XML

new⇒I hate PHP

Elliot Anderson,

Dude!! You the​man! The reverse replacement for​array_u...

Alex Ndungu: Oct 11, 1:35am

Call a function from a string in Python

?!code:
some_object.__getattribute​__('method_name')()
?!/code

is​the s...

Patrick Corcoran: Oct 8, 3:53pm

Spider solitaire

I have won 185 games of Spider​Solitaire at the "Difficult" level.​ What is...

75.179.28.113: Oct 8, 12:42pm

Sed one-liners

Hi.

I wanted to let you know​that I wrote an article "Famous Sed​One-Lin...

Peteris Krumins: Oct 8, 3:05am

Timesheet Calculator

Hadn't seen it before now, but my​company already uses a time​tracking prog...

Keith: Oct 7, 10:44am

Girls, please don't get breast implants

Hey everyone, 

I am new to this​blog and I have enjoyed reading all​your...

Sarah.M.: Oct 6, 9:45am

Generated in about 0.055s.

(Used 7 db queries)

mobile phone