Home / guides   Print version

Install LZF on php

This is a small tutorial to install lzf on php.
Using download and compile, it should work on every system.
I tested it on kubuntu 12.04.

lzf is a very high-speed compression with a reasonable compression ratio. Like zip but faster.
The bigger your text is (more characters),
the better the compression gets.

If you want to store the compressed string in a database, make sure it is bitsafe.
e.g. use blob (binary large object).

Download the latest version from:
http://pecl.php.net/package/lzf

cd /usr/src/lzf
wget http://pecl.php.net/get/LZF-1.6.2.tgz

tar xf LZF-1.6.2.tgz

Next you need to prepare it for php5 and configure it

cd LZF-1.6.2
phpize
./configure
Then compile, test and install
install need to be done as root, so use sudo
make
make test
sudo make install

Tell PHP to load the lsf.so module.
add the following line to /etc/php5/apache2/php.ini

extension=lzf.so
Probably best to also add it for cli:
/etc/php5/cli/php.ini

Don't forget to reload Apache:

sudo /etc/init.d/apache2 reload
Now test your php script with lzf-functions:
$ziped_txt=lzf_compress("This is a test of lzf on php; test is done");

print $ziped_txt."\n\n";

print lzf_decompress($ziped_txt)

 

TOP