This repository has been archived by the owner on May 27, 2022. It is now read-only.
forked from phadej/igbinary
-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
114 lines (82 loc) · 3.53 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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. About 50%
reduction in storage requirement can be expected. Specific number depends on
your data. (Un)serialization performance is at least on par with the standard
PHP serializer.
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
- Compatible with PHP5 (tested with 5.2.4 and 5.2.5)
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. Strings are stored only once by using a hash table. Arrays of associate
arrays with very verbose keys are stored very compactly.
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
extension=igbinary.so
# Use igbinary as session serializer
session.serialize_handler=igbinary
.. and in your php code replace serialize and unserialize function calls
with ``igbinary_serialize`` and ``igbinary_unserialize``.
Installing
----------
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"
Compiling:
1. phpize
With GCC:
2. ./configure CFLAGS="-O2 -g" --enable-igbinary
With ICC (Intel C Compiler)
2. ./configure CFLAGS=" -no-prec-div -O3 -xO -unroll2 -g" CC=icc --enable-igbinary
3. make
4. ( make test )
5. make install
6. igbinary.so is installed to the default extension directory
Bugs & Contributions
--------------------
Mailing list for bug reports and other development discussion can be found
at http://groups.google.com/group/igbinary
The preferred ways for contributions are pull requests and email patches
(in git format). Feel free to fork at http://github.com/dynamoid/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.
Trivia
------
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/)