Messagepack serialization Format

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.