= 4.0.4, PHP 5, PHP 7, PHP 8)ob_gzhandler — 在ob_start中使用的用來壓縮輸出緩沖區(qū)中內(nèi)容的回調(diào)函數(shù)。ob_start callback function to gzip output buffer說明ob_gz">

ob_gzhandler

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

ob_gzhandler在ob_start中使用的用來壓縮輸出緩沖區(qū)中內(nèi)容的回調(diào)函數(shù)。ob_start callback function to gzip output buffer

說明

ob_gzhandler(string $buffer, int $mode): string

ob_gzhandler()目的是用在ob_start()中作回調(diào)函數(shù),以方便將gz 編碼的數(shù)據(jù)發(fā)送到支持壓縮頁面的瀏覽器。在ob_gzhandler()真正發(fā)送壓縮過的數(shù)據(jù)之前,該 函數(shù)會確定(判定)瀏覽器可以接受哪種類型內(nèi)容編碼("gzip","deflate",或者根本什么都不支持),然后 返回相應(yīng)的輸出。 所有可以發(fā)送正確頭信息表明他自己可以接受壓縮的網(wǎng)頁的瀏覽器,都可以支持。 All browsers are supported since it's up to the browser to send the correct header saying that it accepts compressed web pages. 如果一個瀏覽器不支持壓縮過的頁面,此函數(shù)返回false

參數(shù)

buffer

mode

返回值

更新日志

版本 說明
4.0.5 填加了 mode 參數(shù)。

范例

示例 #1 ob_gzhandler() example

<?php

ob_start
("ob_gzhandler");

?>
<html>
<body>
<p>This should be a compressed page.</p>
</html>
<body>

注釋

注意:

ob_gzhandler() 需要 zlib 擴展。

注意:

不能同時使用ob_gzhandler()zlib.output_compression。 也要注意使用 zlib.output_compression 要優(yōu)于 ob_gzhandler()。

參見

  • ob_start() - 打開輸出控制緩沖
  • ob_end_flush() - 沖刷出(送出)輸出緩沖區(qū)內(nèi)容并關(guān)閉緩沖