PHP 8.3.4 Released!

bzcompress

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

bzcompress文字列をbzip2形式のデータに圧縮する

説明

bzcompress(string $data, int $block_size = 4, int $work_factor = 0): string|int

bzcompress() は、与えられた文字列を圧縮し、 bzip2 形式のデータとして返します。

パラメータ

data

圧縮する文字列

block_size

圧縮時のブロック長を指定します。 1 から 9 の数とする必要があります。この場合、9 の圧縮度が最大ですが、リソースの消費量も最大となります。

work_factor

繰り返しが多い、最悪の入力データの場合の圧縮処理の動作を制御します。 この値は、0 から 250 までとなり、0 は特別な場合です。

work_factor によらず、 生成される出力は同じになります。

戻り値

圧縮された文字列、もしくはエラー時はエラー数

例1 データの圧縮

<?php
$str
= "sample data";
$bzstr = bzcompress($str, 9);
echo
$bzstr;
?>

参考

add a note

User Contributed Notes 2 notes

up
7
uprz23 at gmail dot com
13 years ago
Comparing gzcompress/gzuncompress and bzcompress/bzdecompress, the bz combo is about 5x slower than gz.
up
4
diego a messenger do dsemmler do de
14 years ago
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
To Top