Igbinary

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
Implementation

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.

  1. 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.
  2. Numerical values are stored in the smallest primitive data type available: 123 = int8_t, 1234 = int16_t, 123456 = int32_t ... and so on.
How to use?

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值