~ufirst/phpredis/igbinary

« back to all changes in this revision

Viewing changes to igbinary-1.2.1/README.md

  • Committer: Michael Ruoss
  • Date: 2015-03-18 14:12:19 UTC
  • Revision ID: git-v1:c591bdc61de714458440ff13454bc51d94ab5f3d
new build info structure

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
igbinary
 
2
========
 
3
 
 
4
[![Build Status](https://travis-ci.org/igbinary/igbinary.svg?branch=master)](https://travis-ci.org/igbinary/igbinary)
 
5
 
 
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
 
11
your data.
 
12
 
 
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
 
19
it, a bit faster.
 
20
 
 
21
Features
 
22
--------
 
23
 
 
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
 
33
 
 
34
Implementation details
 
35
----------------------
 
36
 
 
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):
 
40
 
 
41
1. Array keys are repeated redundantly.
 
42
2. Numerical values are plain text.
 
43
3. Human readability adds some overhead.
 
44
 
 
45
Igbinary uses two specific strategies to minimize the size of the serialized
 
46
output.
 
47
 
 
48
1. Repetitive strings are stored only once. Collections of objects benefit
 
49
   significantly from this. See "compact_strings" option.
 
50
 
 
51
2. Numerical values are stored in the smallest primitive data type
 
52
   available:
 
53
    *123* = `int8_t`,
 
54
    *1234* = `int16_t`,
 
55
    *123456* = `int32_t`
 
56
 ... and so on.
 
57
 
 
58
3. ( Well, it is not human readable ;)
 
59
 
 
60
How to use
 
61
----------
 
62
 
 
63
Add the following lines to your php.ini:
 
64
 
 
65
    ; Load igbinary extension
 
66
    extension=igbinary.so
 
67
 
 
68
    ; Use igbinary as session serializer
 
69
    session.serialize_handler=igbinary
 
70
 
 
71
    ; Enable or disable compacting of duplicate strings
 
72
    ; The default is On.
 
73
    igbinary.compact_strings=On
 
74
 
 
75
    ; Use igbinary as serializer in APC cache (3.1.7 or later)
 
76
    ;apc.serializer=igbinary
 
77
 
 
78
.. and in your php code replace serialize and unserialize function calls
 
79
with `igbinary_serialize` and `igbinary_unserialize`.
 
80
 
 
81
Installing
 
82
----------
 
83
 
 
84
Note:
 
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"
 
87
 
 
88
1. `phpize`
 
89
2. `./configure:
 
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`
 
93
3. `make`
 
94
4. `make test`
 
95
5. `make install`
 
96
6. igbinary.so is installed to the default extension directory
 
97
 
 
98
### To run APCu test
 
99
 
 
100
```
 
101
# go to modules directory
 
102
cd modules
 
103
 
 
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
 
107
```
 
108
 
 
109
Similar approach should work for APC.
 
110
 
 
111
Bugs & Contributions
 
112
--------------------
 
113
 
 
114
Mailing list for bug reports and other development discussion can be found
 
115
at http://groups.google.com/group/igbinary
 
116
 
 
117
Fill bug reports at
 
118
https://github.com/igbinary/igbinary/issues
 
119
 
 
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
 
122
 
 
123
Utilizing in other extensions
 
124
-----------------------------
 
125
 
 
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.
 
130
 
 
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.
 
133
 
 
134
Trivia
 
135
------
 
136
 
 
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/)
 
141
 
 
142