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.
__autoload
& unserialize_callback_func
__sleep
& __wakeup
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):
Igbinary uses two specific strategies to minimize the size of the serialized output.
Repetitive strings are stored only once. Collections of objects benefit significantly from this. See "compact_strings" option.
Numerical values are stored in the smallest primitive data type available: 123 = int8_t
, 1234 = int16_t
, 123456 = int32_t
... and so on.
( Well, it is not human readable ;)
Add the following lines to your 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
.. 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"
phpize
./configure CFLAGS="-O2 -g" --enable-igbinary
./configure CFLAGS=" -no-prec-div -O3 -xO -unroll2 -g" CC=icc --enable-igbinary
./configure CC=clang CFLAGS="-O0 -g" --enable-igbinary
make
make test
make install
# go to modules directory
cd modules
# ... and create symlink to apcu extension
# it will be loaded during test suite
/opt/lib/php/extensions/no-debug-non-zts-20121212/apcu.so
Similar approach should work for APC.
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 extensionsIgbinary 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/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4