Home  >  Article  >  php教程  >  PHP试用MessagePack

PHP试用MessagePack

WBOY
WBOYOriginal
2016-06-06 20:07:481308browse

Its like JSON. but fast and small. 这句吸引了我,去瞧了下。 官网:http://msgpack.org 官方的安装方法忽悠人,msgpack目录下根本没php目录...只看到csharp,erlang,go,java,ruby等目录。 引用 git clone https://github.com/msgpack/msgpack.git cd msgpa

It's like JSON. but fast and small.

这句吸引了我,去瞧了下。

官网:http://msgpack.org

官方的安装方法忽悠人,msgpack目录下根本没php目录...只看到csharp,erlang,go,java,ruby等目录。

引用


git clone https://github.com/msgpack/msgpack.git
cd msgpack/php
phpize
./configure && make && make install



还是在PHP官网扩展找到了:http://pecl.php.net/package/msgpack
最后更新时间:2012-09-14,昨天的版本。
附安装过程:

wget http://pecl.php.net/get/msgpack-0.5.2.tgz
tar zxf msgpack-0.5.2.tgz
cd msgpack-0.5.2
/usr/local/hx/php/bin/phpize
./configure --with-php-config=/usr/local/hx/php/bin/php-config
make && make install


然后把msgpack.so加到php.ini里,重启php,完成安装。

开始测试:
$data = array(0=>'abcdefghijklmnopqrstuvwxyz',1=>'厦门','abc'=>'1234567890');

分别对其msgpack_pack,json_encode,serialize,长度为:50,62,87
然后分别执行10000次,耗时:9.95 毫秒,17.45 毫秒,8.85 毫秒
解开执行10000次,耗时:14.76 毫秒,23.93 毫秒,14.61 毫秒

msgpack的性能至少超过json50%,虽然和serialize其实速度差不多,但serialize占用空间明显比较多。

另外,GBK的程序方便了,中文也可以msgpack_pack,用json的话还要批量转换成utf-8之后才能json_encode。
Tags - php , jsonPHP试用MessagePack
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn