Messagepack is an efficient binary serialization format. As with JSON, you can transform data in multiple languages, but with JSON, it's faster and less data is converted.
Installation
1. Download Msgpack, download the address: Click to download
Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/
2. Compile and install
/usr/bin/phpize (phpize Path)
./configure make
&& make install
3. Add in PHP.ini
Extension = "msgpack.so"
Example: Encode and decode
<?php
$data = Array (' name ' => ' fdipzone ', ' Gender ' => ' man ');
$msg = Msgpack_pack ($data); Encode
$newdata = Msgpack_unpack ($msg);//decode
Print_r ($newdata);
>
Example: Comparison vs. JSON size
<?php
$data = Array (' name ' => ' fdipzone ', ' Gender ' => ' man ');
$msg = Msgpack_pack ($data);
$msg _json = Json_encode ($data);
Echo ' Msgpack: '. strlen ($msg). ' <br> ';
Echo ' JSON: '. strlen ($msg _json);
?>
Author: csdn blog proud Snow star Maple