Home / guides   Print version

Install LZF on php (Gentoo)

This is a small tutorial to install lzf on php.
For a general install with tarball and make go here

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).

This is specific for a installation on Gentoo linux.
Other linux flavors should use there own package managers.

You need to install dev-php/pecl-lzf
it is specified for php5.3

USE="" PHP_TARGETS="php5-3" emerge -q dev-php/pecl-lzf
I needed to add
=dev-php/pecl-lzf-1.6.2 ~amd64
to /etc/portage/package.accept_keywords else it wouldn't compile.

Make sure you use php5.3 for Apache or CLI.
Do this with the following:

eselect php list cli
  [1]   php5.3
  [2]   php5.4 *

eselect php set cli 1
eselect php set apache2 1
You don't have to set cli and apache to the same php-version, (you can even set a different php-version for different websites) But it makes troubleshooting a lot easier.

Don't forget to restart Apache:

/etc/init.d/apache2 restart
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)