Why using igbinary ?

  • You don’t need textual representation
  • Store data into memcached or APC
  • Want to serialize complex data structure

Installation ( Ubuntu 10.10 )

If you are using php5.3 like me , you’ll need phpize5 for compiling this extension.

sudo apt-get install php5-dev
wget http://opensource.dynamoid.com/igbinary-1.1.1.tar.gz
tar -xvf igbinary-1.1.1.tar.gz
cd igbinary-1.1.1/
phpize5
./configure CFLAGS="-O2 -g" --enable-igbinary
make
make test
sudo make install
Don't forget to enable this extension in your conf file or php.ini.
;Load igbinary extension
extension=igbinary.so

;Use igbinary as session serializer
session.serialize_handler=igbinary

;Enable or disable compacting of duplicate strings
; # The default is On.
igbinary.compact_strings=On

;Use igbinary as serializer in APC cache (3.1.7 or later)
;apc.serializer=igbinary

Benchmark

Loop size : 100000

sample file ( Album1 )

space serialize unserialize
PHP 1185 1.352 1.651
igbinary 415 1.212 1.060
% 35.02% 89.64% 64.18%

sample file ( Album2 )

space serialize unserialize
PHP 2682 3.203 3.865
igbinary 832 2.509 2.521
% 31.02% 78.33% 65.22%

sample file ( Matrix )

space serialize unserialize
PHP 2682 3.203 3.865
igbinary 832 2.509 2.521
% 31.02% 78.33% 65.22%

sample file ( Scalar )

space serialize unserialize
PHP 534 0.912 0.923
igbinary 258 0.516 0.627
% 48.31% 56.56% 67.88%

sample file ( Simple )

space serialize unserialize
PHP 5 0.042 0.033
igbinary 6 0.029 0.031
% 120% 69.80% 93.96%

sample file

space serialize unserialize
PHP 46 0.075 0.099
igbinary 20 0.129 0.078
% 43.48% 170.86% 78.71%

The benchmark script done by Teddy Grenman creator of igbinary. Those test have been done on a Virtual Ubuntu machine with only 512M of memory. Next step : test it with memcached storing session data.