ob_gzhandler автоматически обнаружит, совместим ли браузер пользователей с gz.
Это также автоматически изменит ваши заголовки.
Он не обнаружит, работает ли apache mod_deflate или mod_gzip (и кто в любом случае говорит, что вы используете Apache!)
if(!ob_start("ob_gzhandler")) ob_start();
/* insert code here then flush the buffer to $buffer */
$cacheTime = time(); // or the file date of your static file
$gmt_mtime = gmdate('D, d M Y H:i:s', $cacheTime ) . ' GMT';
header("Content-type: text/css; charset=utf-8");
header("Last-Modified: " . $gmt_mtime ,true);
header('Content-Length: ' . strlen($buffer),true);
header("Expires: " . gmdate("D, d M Y H:i:s", $cacheTime + $seconds) . " GMT",true);
header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate",true);
header("Cache-Control: post-check=0, pre-check=0", FALSE);
echo $buffer;