ob_gzhandler() - php 输出缓冲函数
ob_gzhandler()
(PHP 4 >= 4.0.4, PHP 5, PHP 7)
在ob_start中使用的用来压缩输出缓冲区中内容的回调函数。ob_start callback function to gzip output buffer
说明
ob_gzhandler(string $buffer, int $mode) : stringob_gzhandler()目的是用在ob_start()中作回调函数,以方便将gz 编码的数据发送到支持压缩页面的浏览器。在ob_gzhandler()真正发送压缩过的数据之前,该函数会确定(判定)浏览器可以接受哪种类型内容编码("gzip","deflate",或者根本什么都不支持),然后返回相应的输出。所有可以发送正确头信息表明他自己可以接受压缩的网页的浏览器,都可以支持。 All browsers are supported since it's up to the browser to send the correct header saying that it accepts compressed web pages.如果一个浏览器不支持压缩过的页面,此函数返回FALSE
。
参数
$buffer$mode
返回值
更新日志
版本 | 说明 |
---|---|
4.0.5 | 填加了$mode参数。 |
范例
Example #1ob_gzhandler()example
This should be a compressed page.
注释
Note:
ob_gzhandler()需要 zlib 扩展。
Note:
不能同时使用ob_gzhandler()和 zlib.output_compression。也要注意使用 zlib.output_compression 要优于ob_gzhandler()。
参见
ob_start()
打开输出控制缓冲ob_end_flush()
冲刷出(送出)输出缓冲区内容并关闭缓冲
I've just spent 5 hours fighting a bug in my application and outcome is: W3C Standart requires response body to be empty if 304 header set. With compression on it will at least contain a gzip stream header even if your output is completely empty! This affects firefox (current ver.3.6.3) in a very subtle way: one of the requests after the one that gets 304 with not empty body gets it response prepended with contents of that body. In my case it was a css file and styles was not rendered at all, which made problem show up.
The simplest way for gzip compression is: ob_start("ob_gzhandler") returns FALSE if browser doesn't support gzip, so then is called normal ob_start();
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:
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!