PHP输出gzip压缩

function ob_gzip($content){
    if(!headers_sent()&&extension_loaded("zlib")&&strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")){
        $content = gzencode($content,9);
        header("Content-Encoding: gzip");
        header("Vary: Accept-Encoding");
        header("Content-Length: ".strlen($content));
    }
    return $content;
}
ob_start('ob_gzip'); //函数名
echo "这是测试字符串这是测试字符串这是测试字符串";
ob_end_flush();

你可能感兴趣的:(PHP)