Created
October 30, 2015 09:18
-
-
Save eugeneglova/cd22a3e8327e1132d60c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL & ~E_WARNING); | |
// cache time in seconds | |
$cache_time = 5 * 60; // 5 mins | |
$time = floor(time() / $cache_time) * $cache_time; | |
// Getting headers sent by the client. | |
$headers = apache_request_headers(); | |
// Checking if the client is validating his cache and if it is current. | |
if (isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == $time)) { | |
// Client's cache IS current, so we just respond '304 Not Modified'. | |
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT', true, 304); | |
} else { | |
// Image not cached or cache outdated, we respond '200 OK' and output the image. | |
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT', true, 200); | |
} | |
?> | |
hello world <?php echo time(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment