com web/php: Cache the images for a day: images/elephpants.php

From: Date: Sat, 07 Dec 2013 01:00:35 +0000
Subject: com web/php: Cache the images for a day: images/elephpants.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-17430@lists.php.net to get a copy of this message
Commit: 206aab8bf2a0fff87e5453eaeb4545bacd63ee36 Author: Hannes Magnusson <bjori@mongodb.com> Fri, 6 Dec 2013 17:00:35 -0800 Parents: 9098464a05bab5ebb92dfad27c7cee77e2663965 Branches: master Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=206aab8bf2a0fff87e5453eaeb4545bacd63ee36 Log: Cache the images for a day Changed paths: M images/elephpants.php Diff: diff --git a/images/elephpants.php b/images/elephpants.php index 88d4185..f957878 100644 --- a/images/elephpants.php +++ b/images/elephpants.php @@ -1,5 +1,21 @@ <?php include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc'; + +$now = $_SERVER["REQUEST_TIME"]; +if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) { + $last = strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]); + + /* Use the same logo for a day */ + if (strtotime("+1 day", $last) > $now) { + header("HTTP/1.1 304 Not Modified"); + exit; + } +} +$future = strtotime("+1 day", $now); +$tsstring = gmdate("D, d M Y H:i:s ", $now) . "GMT"; +header("Last-Modified: " . $tsstring); +header("Expires: " . date(DATE_RSS, $future)); + /* Simple script to serve elephpant images in json format.

« previous php.webmaster (#17430) next »