Igbinary is a drop in replacement for the standard php serializer.
C PHP C++ M4 Other
Pull request Compare This branch is 213 commits ahead of somia:master.
Latest commit 72d5a81 Jul 7, 2017 @TysonAndre TysonAndre committed on GitHub Merge pull request #139 from TysonAndre/add-php7.2-alpha2
Add php7.2 alpha2
Failed to load latest commit information.
benchmark Add simple and remove ol benmarking scripts. Jul 22, 2012
ci Make 32-bit builds from source use 7.2.0alpha2, as well Jul 8, 2017
src Update everything(package.xml/docs/reflection) for the 2.0.4 release Apr 14, 2017
tests change test to pass with 7.2.0-dev Apr 13, 2017
.gitignore Rename package2.xml to package.xml Aug 29, 2014
.travis.yml Make 32-bit builds from source use 7.2.0alpha2, as well Jul 8, 2017
COPYING PECL stuff, updated COPYING Aug 28, 2014
CREDITS Add myself to CREDITS Jul 30, 2016
Makefile.bench Add simple and remove ol benmarking scripts. Jul 22, 2012
NEWS Update everything(package.xml/docs/reflection) for the 2.0.4 release Apr 14, 2017
README.md Enable tests of 7.1 releases, stop testing RCs Dec 3, 2016
WINDOWS.md Update everything(package.xml/docs/reflection) for the 2.0.4 release Apr 14, 2017
appveyor.yml Bump php windows test version to 7.1, update windows env variables Jun 10, 2017
config.m4 Fix the config.m4 pecl builds Nov 30, 2016
config.w32 Stop checking for ext/apc in php 7 Nov 20, 2016
igbinary.h Fixes main/internal_functions_cli.c ... error: ‘phpext_igbinary_ptr’ … Mar 28, 2017
igbinary.php Initial commit Mar 21, 2009
igbinary.php.ini Add option to disable compacting of duplicate strings. Oct 2, 2009
igbinary.spec Another rm check Dec 31, 2009
package.xml drop outdated files Apr 24, 2017
php_igbinary.h Fixes main/internal_functions_cli.c ... error: ‘phpext_igbinary_ptr’ … Mar 28, 2017
tags.sh Don't duplicate tags.sh. Run ../../tags.sh instead Jul 30, 2016



Build Status Build status (Windows)

Igbinary is a drop in replacement for the standard php serializer. Instead of time and space consuming textual representation, igbinary stores php data structures in compact binary form. Savings are significant when using memcached or similar memory based storages for serialized data. About 50% reduction in storage requirement can be expected. Specific number depends on your data.

Unserialization performance is at least on par with the standard PHP serializer. Serialization performance depends on the "compact_strings" option which enables duplicate string tracking. String are inserted to a hash table which adds some overhead. In usual scenarios this does not have much significance since usage pattern is "serialize rarely, unserialize often". With "compact_strings" option igbinary is usually a bit slower than the standard serializer. Without it, a bit faster.


  • Supports same data types as the standard PHP serializer: null, bool, int, float, string, array and objects.
  • __autoload & unserialize_callback_func
  • __sleep & __wakeup
  • Serializable -interface
  • Data portability between platforms (32/64bit, endianess)
  • Tested on Linux amd64, Linux ARM, Mac OSX x86, HP-UX PA-RISC and NetBSD sparc64
  • Hooks up to APC opcode cache as a serialization handler (APC 3.1.7+) (Hooks up to the substitute APCu for recent php releases)
  • Compatible with PHP 5.2 – 5.6, 7.0 – 7.1

Implementation details

Storing complex PHP data structures like arrays of associative arrays with the standard PHP serializer is not very space efficient. The main reasons in order of significance are (at least in our applications):

  1. Array keys are repeated redundantly.
  2. Numerical values are plain text.
  3. Human readability adds some overhead.

Igbinary uses two specific strategies to minimize the size of the serialized output.

  1. Repetitive strings are stored only once. Collections of objects benefit significantly from this. See "compact_strings" option.

  2. Numerical values are stored in the smallest primitive data type available: 123 = int8_t, 1234 = int16_t, 123456 = int32_t ... and so on.

  3. ( Well, it is not human readable ;)

How to use

Add the following lines to your php.ini:

; Load igbinary extension

; Use igbinary as session serializer

; Enable or disable compacting of duplicate strings
; The default is On.

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

.. and in your php code replace serialize and unserialize function calls with igbinary_serialize and igbinary_unserialize.


Note: Sometimes phpize must be substituted with phpize5. In such cases the following option must be given to configure script: "--with-php-config=.../php-config5"

  1. phpize
  2. `./configure:
    • With GCC: ./configure CFLAGS="-O2 -g" --enable-igbinary
    • With ICC (Intel C Compiler) ./configure CFLAGS=" -no-prec-div -O3 -xO -unroll2 -g" CC=icc --enable-igbinary
    • With clang: ./configure CC=clang CFLAGS="-O0 -g" --enable-igbinary
  3. make
  4. make test
  5. make install
  6. igbinary.so is installed to the default extension directory

To run APCu test

# go to modules directory
cd modules

# ... and create symlink to apcu extension
# it will be loaded during test suite

Similar approach should work for APC.

Installing on Windows

If you are a contributor to/packager of igbinary, see WINDOWS.md

Bugs & Contributions

Mailing list for bug reports and other development discussion can be found at http://groups.google.com/group/igbinary

Fill bug reports at https://github.com/igbinary/igbinary/issues

The preferred ways for contributions are pull requests and email patches (in git format). Feel free to fork at http://github.com/igbinary/igbinary

Utilizing in other extensions

Igbinary can be called from other extensions fairly easily. Igbinary installs its header file to ext/igbinary/igbinary.h. There are just two straighforward functions: igbinary_serialize and igbinary_unserialize. Look at igbinary.h for prototypes and usage.

Add PHP_ADD_EXTENSION_DEP(yourextension, igbinary) to your config.m4 in case someone wants to compile both of them statically into php.


Where does the name "igbinary" come from? There was once a similar project called fbinary but it has disappeared from the Internet a long time ago. Its architecture wasn't particularly clean either. IG is an abbreviation for a finnish social networking site IRC-Galleria (http://irc-galleria.net/)