From fb3eca0b0760ed07e9b72eefd42a7732677c81b7 Mon Sep 17 00:00:00 2001 From: Philipp Matthias Hahn Date: Wed, 11 Jan 2012 23:14:26 +0100 Subject: [PATCH] Use If-Modified-Since-HTTP-Header Skip downloading a potentially huge calendar file if it the same as out local copy, using the If-Modified-Since-HTTP-Header. Signed-off-by: Andrew McMillan --- inc/external-fetch.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/external-fetch.php b/inc/external-fetch.php index 49506c3a..fe0f1962 100644 --- a/inc/external-fetch.php +++ b/inc/external-fetch.php @@ -55,14 +55,17 @@ function fetch_external ( $bind_id, $min_age = '1 hour' ) $sql .= ' ORDER BY modified DESC LIMIT 1'; $qry = new AwlQuery( $sql, $params ); if ( $qry->Exec('DAVResource') && $qry->rows() > 0 && $row = $qry->Fetch() ) { + $local_ts = new DateTime($row->modified); $curl = curl_init ( $row->external_url ); curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $curl, CURLOPT_HEADER, true ); curl_setopt ( $curl, CURLOPT_FILETIME, true ); curl_setopt ( $curl, CURLOPT_NOBODY, true ); + curl_setopt ( $curl, CURLOPT_TIMEVALUE, $local_ts->format("U") ); + curl_setopt ( $curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE ); $ics = curl_exec ( $curl ); $info = curl_getinfo ( $curl ); - if ( isset($info['filetime']) && new DateTime("@" . $info['filetime']) <= $local_ts ) { + if ( $info['http_code'] === 304 || isset($info['filetime']) && new DateTime("@" . $info['filetime']) <= $local_ts ) { dbg_error_log("external", "external resource unchanged " . $info['filetime'] ); curl_close ( $curl ); // BUGlet: should track server-time instead of local-time