php教程

bzcompress

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

bzcompress把一个字符串压缩成 bzip2 编码数据

说明

bzcompress ( string $source [, int $blocksize = 4 [, int $workfactor = 0 ]] ) : mixed

bzcompress() 压缩了指定的字符串并以 bzip2 编码返回数据。

参数

source

待压缩的字符串。

blocksize

指定压缩时使用的块大小,应该是一个 1-9 的数字。9 可以有最高的压缩比,但会使用更多的资源。

workfactor

控制压缩阶段出现最坏的重复性高的情况下输入数据时的行为。 该值可以是在 0 至 250 之间,0是一个特殊的情况。

无论 workfactor是什么,产生的输出都是一致的。

返回值

压缩后的字符串,或者在出现错误时返回错误号。

范例

Example #1 压缩数据

<?php
$str 
"sample data";
$bzstr bzcompress($str9);
echo 
$bzstr;
?>

参见

User Contributed Notes

uprz23 at gmail dot com 24-Jun-2010 12:52
Comparing gzcompress/gzuncompress and bzcompress/bzdecompress, the bz combo is about 5x slower than gz.
diego a messenger do dsemmler do de 24-Apr-2009 03:01
The blocksize parameter tells bzip to use 100 000 Byte * blocksize blocks to compress the string. In the example above we can see the output size and time needed of bz[2] to bz[9] are nearly the same, because there ware just 189 058 Byte of data to compress and in this case bz[2] to bz[9] means "compress all data et once".
So we may notice a bigger difference in speed and compression rate with bigger files.

the workfactor parameter sets, how fast bzip switches in the slower fallback algorithm, if the standard algorithm gets problems with much repetitive data. 0 means, bzip uses the default value of 30. This option is recommend.

For more information about the parameter look at http://www.bzip.org/1.0.3/html/low-level.html#bzcompress-init

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788