php if none match,关于Etag/If-None-Match的用法

关于Last-Modified/If-Modified-Since及Etag/If-None-Match的用法

相关代码if (method_exists($controller, $action)) {

ob_start();

$controller -> {$action}();

$content = ob_get_contents();

ob_end_clean();

$etag = md5($content); //计算输出内容的md5

fheader('Etag: ' . $etag); //服务器端输出Etag header

//判断浏览器发送过来的If-None-Match头与服务器端的etag值是否相等

if ($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {

write_log(sprintf("%s Client HTTP_IF_NONE_MATCH:|%s| and Server Etag:|%s| is same, send 304 header!", __METHOD__, $_SERVER['HTTP_IF_NONE_MATCH'], $etag));

fheader('HTTP/1.1 304 Not Modified!'); //相等,直接向浏览器发送304状态码,浏览器则直接取本地的缓存数据,节省带宽,提高页面响应速度

} else {

write_log(sprintf("%s file content already modified, output content!", __METHOD__));

echo $content;

<

你可能感兴趣的:(php,if,none,match)