[go: nahoru, domu]

CascadiaPHP 2024

Voting

: four minus three?
(Example: nine)

The Note You're Voting On

m at rtij dot nl
19 years ago
All versions of MSIE have a bug where they don't cache gzipd contents. If your application depends on caching, this is something to keep in mind. In the end, I did:

<?php

// These are so benificial, they default to true.
if (!isset($use_page_cache))
$use_page_cache = 1;
if (!isset(
$use_compression))
$use_compression = 1;

// Add browsers here as we must detect them. Opera is an oddball, if we don't detect
// it specifically, it will turn up as MSIE

$browser="other";
if (isset(
$_SERVER['HTTP_USER_AGENT'])) {
$agent = $_SERVER['HTTP_USER_AGENT'];
if (
eregi("opera",$agent)){
$browser="opera";
}elseif(
eregi("msie",$agent)){
$browser="msie";
}
}

if (
$use_compression && !( $use_page_cache && $browser == "msie")) {
// Turn on compression, makes quite a difference in bandwith usage.
// However, MSIE (all versions) have a bug with compression and caching. So for MSIE
// it's either compression or caching. We choose caching.
ob_start('ob_gzhandler');
}

session_cache_limiter("must-revalidate");

session_start();

// ... put stuff in $content ...

if ($use_page_cache) {
// MD5 is slow, however with a fast server (PIII or better) we should be OK
$hash = md5($content);
$headers = getallheaders();
if (isset(
$headers['If-None-Match']) && ereg($hash, $headers['If-None-Match']))
{
header('HTTP/1.1 304 Not Modified');
exit;
}
header("ETag: \"$hash\"");
}

print
$content;

?>

<< Back to user notes page

To Top