我正在测试我的网站,我使用ob_gzhandler压缩输出并得到一个有趣的错误。根据文档“如果浏览器不支持压缩页面,则此函数返回FALSE”
这是我的测试代码:
<?php
$res = ob_start( 'ob_gzhandler' ) ;
echo 'My text' ;
var_dump( $res ) ;
我正在使用ff5.0,如果我不更改任何标题,一切正常,这里是列表:
实时HTTP标头输出
http://tester.loc/ob-test/gz.php
GET /ob-test/gz.php HTTP/1.1
Host: tester.loc
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://tester.loc/ob-test/
Cache-Control: max-age=0
HTTP/1.1 200 OK
Date: Wed, 06 Jul 2011 10:37:45 GMT
Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.1
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 126
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
脚本输出:
My text
boolean true
但是当我删除Accept-Encoding标头时,ob_gzhandler仍然返回true。再次列出:
实时HTTP标头输出
http://tester.loc/ob-test/gz.php
GET /ob-test/gz.php HTTP/1.1
Host: tester.loc
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://tester.loc/ob-test/
Cache-Control: max-age=0
HTTP/1.1 200 OK
Date: Wed, 06 Jul 2011 10:35:52 GMT
Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.1
Content-Length: 109
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
脚本输出
My text
boolean true
因此,在两种情况下,ob_gzhandler都会返回true,尽管在第二个示例中它应该是false。这是我的误解还是一个错误?
提前完成
答案 0 :(得分:1)
这是
ob_gzhandler()
函数本身将返回false,这不是你所调用的(直接)。
如果回调失败,ob_start()只返回false,我认为ob_gzhandler()返回false与失败时相同。