2012-01-16 60 views
0

如果我在我的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"; 

?> 

没有输出

+1

你测试过哪个客户端?什么地方的请求头和什么响应? – mario 2012-01-16 22:13:53

+0

事实上,除非客户端发送'Accept-Encoding:gzip'或'Accept-Encoding:deflate'头文件,否则输出不会被自动压缩。 – DaveRandom 2012-01-16 22:19:45

+0

phpinfo()Accept-Encoding:gzip,deflate – lgt 2012-01-16 22:41:38

回答

0

zlib数据输出处理器无关,与日gz文件的功能。

所以还有其他的错误,打开error_reporting

否则显示的代码工作正常。 “无输出”行为不可重现。

+0

我一直在打开错误报告,我得到以下几点:致命错误:调用未定义的函数gzopen()在/var/www/kakuki/zlib.php在线8 我一直在尝试重新编译php,但没有任何结果。在这种情况下,我正在使用--with-zlib。很有趣的是,在phpecho()编译后没有显示出我的变化。 – lgt 2012-01-17 09:58:34