4
[![Build Status](https://travis-ci.org/igbinary/igbinary.svg?branch=master)](https://travis-ci.org/igbinary/igbinary)
6
Igbinary is a drop in replacement for the standard php serializer. Instead of
7
time and space consuming textual representation, igbinary stores php data
8
structures in compact binary form. Savings are significant when using
9
memcached or similar memory based storages for serialized data. About 50%
10
reduction in storage requirement can be expected. Specific number depends on
13
Unserialization performance is at least on par with the standard PHP serializer.
14
Serialization performance depends on the "compact_strings" option which enables
15
duplicate string tracking. String are inserted to a hash table which adds some
16
overhead. In usual scenarios this does not have much significance since usage
17
pattern is "serialize rarely, unserialize often". With "compact_strings"
18
option igbinary is usually a bit slower than the standard serializer. Without
24
- Supports same data types as the standard PHP serializer: null, bool, int,
25
float, string, array and objects.
26
- `__autoload` & `unserialize_callback_func`
27
- `__sleep` & `__wakeup`
28
- Serializable -interface
29
- Data portability between platforms (32/64bit, endianess)
30
- Tested on Linux amd64, Linux ARM, Mac OSX x86, HP-UX PA-RISC and NetBSD sparc64
31
- Hooks up to APC opcode cache as a serialization handler (APC 3.1.7+)
32
- Compatible with PHP 5.2 – 5.6
34
Implementation details
35
----------------------
37
Storing complex PHP data structures like arrays of associative arrays
38
with the standard PHP serializer is not very space efficient. The main
39
reasons in order of significance are (at least in our applications):
41
1. Array keys are repeated redundantly.
42
2. Numerical values are plain text.
43
3. Human readability adds some overhead.
45
Igbinary uses two specific strategies to minimize the size of the serialized
48
1. Repetitive strings are stored only once. Collections of objects benefit
49
significantly from this. See "compact_strings" option.
51
2. Numerical values are stored in the smallest primitive data type
58
3. ( Well, it is not human readable ;)
63
Add the following lines to your php.ini:
65
; Load igbinary extension
68
; Use igbinary as session serializer
69
session.serialize_handler=igbinary
71
; Enable or disable compacting of duplicate strings
73
igbinary.compact_strings=On
75
; Use igbinary as serializer in APC cache (3.1.7 or later)
76
;apc.serializer=igbinary
78
.. and in your php code replace serialize and unserialize function calls
79
with `igbinary_serialize` and `igbinary_unserialize`.
85
Sometimes phpize must be substituted with phpize5. In such cases the following
86
option must be given to configure script: "--with-php-config=.../php-config5"
90
- With GCC: `./configure CFLAGS="-O2 -g" --enable-igbinary`
91
- With ICC (Intel C Compiler) `./configure CFLAGS=" -no-prec-div -O3 -xO -unroll2 -g" CC=icc --enable-igbinary`
92
- With clang: `./configure CC=clang CFLAGS="-O0 -g" --enable-igbinary`
96
6. igbinary.so is installed to the default extension directory
101
# go to modules directory
104
# ... and create symlink to apcu extension
105
# it will be loaded during test suite
106
/opt/lib/php/extensions/no-debug-non-zts-20121212/apcu.so
109
Similar approach should work for APC.
114
Mailing list for bug reports and other development discussion can be found
115
at http://groups.google.com/group/igbinary
118
https://github.com/igbinary/igbinary/issues
120
The preferred ways for contributions are pull requests and email patches
121
(in git format). Feel free to fork at http://github.com/igbinary/igbinary
123
Utilizing in other extensions
124
-----------------------------
126
Igbinary can be called from other extensions fairly easily. Igbinary installs
127
its header file to _ext/igbinary/igbinary.h_. There are just two straighforward
128
functions: `igbinary_serialize` and `igbinary_unserialize`. Look at _igbinary.h_ for
129
prototypes and usage.
131
Add `PHP_ADD_EXTENSION_DEP(yourextension, igbinary)` to your _config.m4_ in case
132
someone wants to compile both of them statically into php.
137
Where does the name "igbinary" come from? There was once a similar project
138
called fbinary but it has disappeared from the Internet a long time ago. Its
139
architecture wasn't particularly clean either. IG is an abbreviation for a
140
finnish social networking site IRC-Galleria (http://irc-galleria.net/)