• Stars
    star
    258
  • Rank 152,757 (Top 4 %)
  • Language
    C
  • License
    Other
  • Created about 15 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Igbinary is a drop in replacement for the standard php serializer. Check https://github.com/igbinary/igbinary for the freshest version

igbinary

Build Status

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.

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, Linux ARM, Mac OSX x86, HP-UX PA-RISC and NetBSD sparc64
  • Hooks up to APC opcode cache as a serialization handler (APC 3.1.7+)
  • Compatible with PHP 5.2 – 5.6

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. Repetitive strings are stored only once. Collections of objects benefit significantly from this. See "compact_strings" option.

  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

; 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.

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"

  1. phpize
  2. `./configure:
    • With GCC: ./configure CFLAGS="-O2 -g" --enable-igbinary
    • With ICC (Intel C Compiler) ./configure CFLAGS=" -no-prec-div -O3 -xO -unroll2 -g" CC=icc --enable-igbinary
    • With clang: ./configure CC=clang CFLAGS="-O0 -g" --enable-igbinary
  3. make
  4. make test
  5. make install
  6. igbinary.so is installed to the default extension directory

To run APCu test

# 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.

Bugs & Contributions

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 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/)

More Repositories

1

optika

Optics library for JavaScript
JavaScript
140
star
2

cabal-fmt

An experiment of formatting .cabal files
Haskell
95
star
3

typify

Runtime type checking for JavaScript
JavaScript
77
star
4

relaxed-json

Relaxed JSON is strict superset JSON, relaxing strictness of vanilla JSON
JavaScript
73
star
5

cabal-extras

A tool suite to aid Haskell development using `cabal-install`
Haskell
68
star
6

write-yourself-a-typed-functional-language

Write yourself a typed functional language
Haskell
65
star
7

menrva

Ambitious data-flow library
JavaScript
36
star
8

kleene

Kleene algebra, regular expressions
Haskell
31
star
9

docker-haskell-example

How to build Docker image for Haskell web app?
Dockerfile
29
star
10

tdigest

On-line accumulation of rank-based statistics such as quantiles and trimmed means
Haskell
29
star
11

overloaded

Overloaded plugin
Haskell
28
star
12

idioms-plugins

Hack idiom-brackets using GHC Source Plugin (8.6+)
Haskell
24
star
13

vec

Nat, Fin, Vec
Haskell
23
star
14

git-badc0de

Make git commits with pretty hashes
C
22
star
15

topograph

Directed Acyclic Graphs
Haskell
20
star
16

graafi

cycle.js expirement
JavaScript
20
star
17

latex-svg

Render LaTeX math to SVG mages
Haskell
16
star
18

acme-kmett

A collection of Edward Kmett's packages in a single repository
Makefile
15
star
19

staged

Staged Streams and other stuff
Haskell
14
star
20

boring

Boring and Absurd types
Haskell
14
star
21

trampa

Trampolines, to emulate tail-recursion.
JavaScript
13
star
22

bound-extras

ScopeT and ScopeH
Haskell
13
star
23

kleene-type

Regular expressions of types
Haskell
13
star
24

trustee

Hackage Trustee helper tool
Haskell
13
star
25

heroku-docker-haskell-test

Heroku + docker + haskell = ?
Shell
13
star
26

preload-trick

"Preload" Haskell packages to override them
Haskell
12
star
27

language-pts

Pure Type Systems
Haskell
12
star
28

docker-ghc

GHC + Cabal docker image
Dockerfile
12
star
29

aws-lambda-haskell-runtime

Build AWS Lambda's with Haskell
Haskell
11
star
30

hooglite

Alternative and lite implementation of Hoogle
Haskell
11
star
31

insert-ordered-containers

Associative containers retating insertion order for traversals
Haskell
11
star
32

saison

Stream Aeson, fruity, spicy, well carbonated.
Haskell
10
star
33

typify-parser

Type signature parser for typify
JavaScript
9
star
34

gists

Oleg's gists
JetBrains MPS
9
star
35

ljs

Generate docs from your source
JavaScript
9
star
36

lens-laws

Existential Optics: discovering correct lens laws
Coq
9
star
37

zinza

Typed templates with jinja like syntax. Docs on Hackage.
Haskell
9
star
38

cabal-refact

Refactoring tool for .cabal files
Haskell
9
star
39

jsstana

s-expression match patterns for Mozilla Parser AST
JavaScript
8
star
40

npm-freeze

Freeze the node dependencies
JavaScript
8
star
41

generic-lens-lite

Lite version of generic-lens
Haskell
7
star
42

file-embed-lzma

Use Template Haskell to embed (LZMA compressed) data.
Haskell
7
star
43

aeson-optics

Law-abiding optics for aeson
Haskell
7
star
44

base64-bytestring-type

A newtype around ByteString, for base64 encoding.
Haskell
6
star
45

singleton-bool

Type level booleans
Haskell
6
star
46

vec-backpack

Haskell
6
star
47

travis-meta-yaml

.travis.yml preprocessor
Haskell
6
star
48

minicsv

Very minimal csv library
Haskell
6
star
49

sasha

A staged lexer generator
Haskell
6
star
50

docker-stackage

Docker image with stackage config
Haskell
5
star
51

lazy-seq

Lazy sequence for JavaScript
JavaScript
5
star
52

regression-simple

Simple linear and quadratic regression
Haskell
5
star
53

JuicyPixels-scale-dct

Scale JuicyPixels images with DCT
Haskell
5
star
54

rc4

RC4 random number generator
JavaScript
5
star
55

binary-tagged

Tagged binary serialisation
Haskell
5
star
56

ncill

Agda mechanization of cut elimination in Non-Commutative Intuitionistic Linear Logic
Agda
5
star
57

dlist-nonempty

Non-empty difference lists
Haskell
5
star
58

spdx

SPDX license expression language - Haskell implementation
Haskell
5
star
59

range-set-list

Memory efficient sets with continuous ranges of elements. List based implementation.
Haskell
5
star
60

rere

recursive regular expressions
Haskell
4
star
61

haskell-monad-http

A MonadHTTP type class
Haskell
4
star
62

minicurl

Minimal bindings to libcurl
Haskell
4
star
63

servant-tiny

A tiny servant version, to learn and experiment
Haskell
4
star
64

libperf

Bindings to Linux perf_event_open functionality
Haskell
4
star
65

time-parsers

Date & time parsers
Haskell
4
star
66

sa

Simulated annealing
Haskell
4
star
67

aeson-compat

Compatibility package for aeson
Haskell
4
star
68

aeson-extra

Extra goodies for aeson
Haskell
4
star
69

hkd

"higher-kinded data"
Haskell
4
star
70

regex-applicative-text

regex-applicative on text
Haskell
4
star
71

staged-gg

Staged GHC.Generics
Haskell
4
star
72

generics-sop-lens

Lenses for types in generics-sop
Haskell
4
star
73

dec

Decidable propositions
Haskell
4
star
74

cabal-env

What cabal-install install --lib could be DEVELOPMENT MOVE TO https://github.com/phadej/cabal-extras
Haskell
4
star
75

mixfix

Mixfix espression parser
JavaScript
4
star
76

nucpp

NuCPP is non-standard not-C preprocessor
Haskell
3
star
77

servant-universe

Megarepository for most servant packages
Makefile
3
star
78

changelog-d

Changelog from the directory of entries
Haskell
3
star
79

representable-fd

Representable functors with FunctionalDependencies
Haskell
3
star
80

end

Evolving non-determinism
Haskell
3
star
81

unsatisfiable

Unsatisfiable type-class
Haskell
3
star
82

ansi-pretty

AnsiPretty type-class for ansi-wl-pprint
Haskell
3
star
83

ghcjs-ubuntu

Packaging GHCJS for Ubuntu
Haskell
3
star
84

th-letrec

Implicit (recursive) let insertion
Haskell
3
star
85

crypt-sha512

Pure Haskell implelementation for GNU SHA512 crypt algorithm
C
3
star
86

gentle-introduction

This is not a prelude, this is gentle introduction
Haskell
3
star
87

step-function

Step functions, staircase functions or piecewise constant functions.
Haskell
2
star
88

servant-blaze

http://hackage.haskell.org/package/servant-blaze
Haskell
2
star
89

helhug-types

Presentation hold at Helsinki Haskell User Group, 2015-03-04
HTML
2
star
90

symbolic

Symbolic Floating
Haskell
2
star
91

agda-np

More programming suited version of All and Any, and other tools I keep reimplementing.
Agda
2
star
92

postgresql-simple-url

Heroku helpers for pulmurice server
Haskell
2
star
93

servant-record

Servant API from a record
Haskell
2
star
94

transformers-quantified

How much stuff breaks?
Haskell
2
star
95

boolean-normal-forms

Boolean normal forms: NNF, DNF & CNF
Haskell
2
star
96

metametapost

A Haskell EDSL to write MetaPost programs
Haskell
2
star
97

servant-cassava

Servant CSV content-type for cassava
Haskell
2
star
98

stackage-extras

Currently: packdeps for everything on Stackage
Haskell
2
star
99

acme-operators

Operators of Haskell, all in one place!
Haskell
2
star
100

github-issues

A barebones issues description context dumper, so you can grep them offline
Haskell
2
star