突然要用到,在这里记一下.
PHP代码
- function ob_gzip($content) { //GZip压缩函数,放在 ob_start() 内,如 ob_start('ob_gzip') !headers_sent()
- if(extension_loaded('zlib')
- && strstr($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip')) {
- $content = gzencode($content."\r\n<!-- GZip Encode -->",5);
- header('Content-Encoding: gzip');
- header('Vary: Accept-Encoding');
- header('Content-Length: '.strlen($content));
- }
- return $content;
- }
- ob_start('ob_gzip');