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 a compact binary form. Savings are significant when using memcached or similar memory based storages for serialized data.
But 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 very clean either. IG is an abbreviation for a Finnish social networking site IRC-Galleria.
Features- 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, Mac OSX x86, HP-UX PA-RISC and NetBSD sparc64
Storing complex PHP data structures like arrays of associative arrays in the standard serialized form is very space inefficient. Igbinary uses two strategies to minimize size of the serialized form.
- Strings are stored only once by using a hash table. Arrays of associate arrays with very verbose keys are stored compactly. Hashing adds some computational overhead but saves memory and bandwidth.
- Numerical values are stored in the smallest primitive data type available: 123 = int8_t, 1234 = int16_t, 123456 = int32_t ... and so on.
First install the extension. Add the following lines to your php.ini:
# Load igbinary extensionextension=igbinary.so# Use igbinary as session serializersession.serialize_handler=igbinary... and in your PHP code replace serialize and unserialize function calls with igbinary_serialize and igbinary_unserialize.