php实现浏览器HTTP/1.1 304 Not Modified方法,通过使用ETag来实现

protected function cache_send($file)
{
	$timestamp = filemtime($file);
	$gmt_mtime=gmdate('r', $timestamp);
	header('ETag: "'.md5($timestamp.$file).'"');
	if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])||isset($_SERVER['HTTP_IF_NONE_MATCH']))
	{
		if ($_SERVER['HTTP_IF_MODIFIED_SINCE']==$gmt_mtime||str_replace('"','',stripslashes($_SERVER['HTTP_IF_NONE_MATCH']))==md5($timestamp.$file))
		{
			header('HTTP/1.1 304 Not Modified');
			exit();
		}
	}
	header('Last-Modified: '.$gmt_mtime);
	header('Cache-Control: public');
	header("Content-type: image/jpeg");
	echo file_get_contents($file);
	exit;
}