1<?php 2/** 3 * Instead of the time and space consuming textual representation used by PHP's `serialize`, 4 * igbinary stores php data structures in a compact binary form. 5 * Memory savings are significant when using memcached, APCu, or similar memory based storages for serialized data. 6 * The typical reduction in storage requirements are around 50%. 7 * The exact percentage depends on your data. 8 * 9 * But where does the name "igbinary" come from? There was once a similar project 10 * called fbinary but it has disappeared from the Internet. Its architecture 11 * wasn't very clean either. IG is short name for a finnish social networking site 12 * {@link http://irc-galleria.net/ IRC-Galleria}. 13 * 14 * Storing complex PHP data structures such as arrays of associative arrays 15 * with the standard PHP serializer is not very space efficient. 16 * Igbinary uses two strategies to minimize the size of the serialized 17 * output. 18 * 19 * 1. Repeated strings are stored only once (this also includes class and property names). 20 * Collections of objects benefit significantly from this. 21 * See the `igbinary.compact_strings` option. 22 * 23 * 2. Integer values are stored in the smallest primitive data type available: 24 * *123* = `int8_t`, 25 * *1234* = `int16_t`, 26 * *123456* = `int32_t` 27 * ... and so on. 28 * 29 * This file is igbinary's phpdoc documentation stub. 30 * 31 * @author Oleg Grenrus <oleg.grenrus@dynamoid.com> 32 * @version 1.0.0 33 * @package igbinary 34 */ 35 36/** 37 * Generates a storable representation of a value. 38 * This is useful for storing or passing PHP values around without losing their type and structure. 39 * To make the serialized string into a PHP value again, use {@link igbinary_unserialize}. 40 * 41 * igbinary_serialize() handles all types, except the resource-type. 42 * You can even serialize() arrays that contain references to itself. 43 * Circular references inside the array/object you are serialize()ing will also be stored. 44 * 45 * If object implements {@link http://www.php.net/~helly/php/ext/spl/interfaceSerializable.html Serializable} -interface, 46 * PHP will call the member function serialize to get serialized representation of object. 47 * 48 * When serializing objects, PHP will attempt to call the member function __sleep prior to serialization. 49 * This is to allow the object to do any last minute clean-up, etc. prior to being serialized. 50 * Likewise, when the object is restored using unserialize() the __wakeup member function is called. 51 * 52 * @param mixed $value The value to be serialized. 53 * @return string Returns a string containing a binary representation of value that can be stored anywhere. 54 * @link http://www.php.net/serialize PHP's default serialize 55 */ 56function igbinary_serialize($value); 57 58/** Creates a PHP value from a stored representation. 59 * igbinary_unserialize() takes a single serialized variable and converts it back into a PHP value. 60 * 61 * If the variable being unserialized is an object, 62 * then after successfully reconstructing the object, 63 * PHP will automatically call the __wakeup() member function (if it exists). 64 * 65 * If the passed in string could not be unserialized, 66 * then NULL is returned and an E_WARNING is issued. 67 * 68 * @param string $str The serialized string. 69 * @return mixed The unserialized value is returned. It can be a boolean, integer, float, string, array, object or null. 70 * @link http://www.php.net/manual/en/function.unserialize.php PHP's default unserialize 71 * @link https://secure.php.net/serializable Serializable interface 72 */ 73function igbinary_unserialize($str); 74