Comparing gzcompress/gzuncompress and bzcompress/bzdecompress, the bz combo is about 5x slower than gz.
bzcompress
(PHP 4 >= 4.0.4, PHP 5)
bzcompress — Verilen dizgiyi bzip2 kodlamalı olarak sıkıştırır
Açıklama
bzcompress() verilen dizgiyi bzip2 türünde sıkıştırır ve bzip2 kodlu veri olarak döndürür.
Değiştirgeler
-
kaynak -
Sıkıştırılacak dizgi.
-
blokboyu -
Sıkıştırma esnasında kullanılacak blok boyu belirtilir. Bu değer 1 ile 9 arasında olmalıdır. 9 değeri en iyi sıkıştırmayı sağlamakla birlikte daha fazla özkaynak kullanır.
-
katsayı -
Bu değer verilen sıkıştırma aşamasının en kötü senaryo durumunda nasıl davranacağını belirtir. (Sık tekrarlı, asimetrik) Bu değer 0 ile 250 arasında değişir. 0 özel bir durumdur.
katsayıdeğerinden bağımsız olarak, üretilen çıktı aynı olur.
Dönen Değerler
Bir hata oluşmamışsa sıkıştırılmış dizgi ile aksi takdirde hata numarası ile döner.
Örnekler
Örnek 1 - Veri sıkıştırma
<?php
$bilgi = "örnek bilgi";
$bzbilgi = bzcompress($bilgi, 9);
echo $bzbilgi;
?>
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
Here is a benchmark comparing strengths of bzip and gzip compression:
gz[0] - 1.647ms - 189058 Byte (100%)
gz[1] - 3.333ms - 44572 Byte (23.58%)
gz[2] - 3.519ms - 42685 Byte (22.58%)
gz[3] - 4.713ms - 40840 Byte (21.6%)
gz[4] - 5.274ms - 39111 Byte (20.69%)
gz[5] - 6.526ms - 37039 Byte (19.59%)
gz[6] - 8.036ms - 36206 Byte (19.15%)
gz[7] - 9.098ms - 35940 Byte (19.01%)
gz[8] - 12.87ms - 35713 Byte (18.89%)
gz[9] - 14.319ms - 35707 Byte (18.89%)
bz[1] - 40.282ms - 32247 Byte (17.06%)
bz[2] - 43.716ms - 29690 Byte (15.7%)
bz[3] - 43.765ms - 29690 Byte (15.7%)
bz[4] - 44.213ms - 29690 Byte (15.7%)
bz[5] - 43.704ms - 29690 Byte (15.7%)
bz[6] - 43.814ms - 29690 Byte (15.7%)
bz[7] - 43.934ms - 29690 Byte (15.7%)
bz[8] - 43.725ms - 29690 Byte (15.7%)
bz[9] - 45.129ms - 29690 Byte (15.7%)
