如果我在我的php.ini中设置zlib压缩支持,将不会真的起作用。php zlib压缩支持将无法工作
zlib.output_compression = On
; http://php.net/zlib.output-compression-level
zlib.output_compression_level = -1
; You cannot specify additional output handlers if zlib.output_compression
; is activated here. This setting does the same as output_handler but in
; a different order.
; http://php.net/zlib.output-handler
;zlib.output_handler =
我使用的PHP 5.3.9
我一直在用下面的PHP代码测试,我必须说,我不是一个专业,但似乎不起作用。
<?php
$filename = tempnam('/tmp', 'zlibtest') . '.gz';
echo "<html>\n<head></head>\n<body>\n<pre>\n";
$s = "Only a test, test, test, test, test, test, test, test!\n";
// open file for writing with maximum compression
$zp = gzopen($filename, "w9");
// write string to file
gzwrite($zp, $s);
// close file
gzclose($zp);
// open file for reading
$zp = gzopen($filename, "r");
// read 3 char
echo gzread($zp, 3);
// output until end of the file and close it.
gzpassthru($zp);
gzclose($zp);
echo "\n";
// open file and print content (the 2nd time).
if (readgzfile($filename) != strlen($s)) {
echo "Error with zlib functions!";
}
unlink($filename);
echo "</pre>\n</body>\n</html>\n";
?>
没有输出
你测试过哪个客户端?什么地方的请求头和什么响应? – mario 2012-01-16 22:13:53
事实上,除非客户端发送'Accept-Encoding:gzip'或'Accept-Encoding:deflate'头文件,否则输出不会被自动压缩。 – DaveRandom 2012-01-16 22:19:45
phpinfo()Accept-Encoding:gzip,deflate – lgt 2012-01-16 22:41:38