据说msgpack是最可能取代json格式,在http接口间传输的数据类型,原因是msgpack更小巧,最近这个火起来是因为golang里面用到了这个,猜的.(msgpack在php5.0里面就支持了,但是一直没有存在感,主要原因就是可读性不好.)
<?php
$str = '{"Account_1":{"table":"accounts","alias":"Account_1","type":"LEFT","conditions":["Account_1.id = Req.account_id"]},"Product_1":{"table":"products","alias":"Product_1","type":"LEFT","conditions":["Product_1.id = Req.product_id"]},"Account_11":{"table":"accounts","alias":"Account_11","type":"LEFT","conditions":["Account_11.id = Product_1.order_account_id"]},"Product_11":{"table":"products","alias":"Product_11","type":"LEFT","conditions":["Product_11.id = Req.HW_SpecialDemand"]}}';
$newstr = msgpack_pack(json_decode($str,true));
dump($newstr,strlen($str),strlen($newstr),msgpack_unpack($newstr));
经对比发现,msgpack确实更小,json格式字符长度是481,msgpack之后是403,
msgpack官网:
https://msgpack.org/
php msgpack源码仓库:
https://github.com/msgpack/msgpack-php
知识补充: