Msgpack
is a PECL
extension that provides an API for serialized communication with MessagePack
.
MessagePack
is an efficient binary-based object serialization class library that can be used for cross-language communication. It can, like JSON, exchange structural objects between many languages; but it is faster and lighter than JSON.
Download
wget https://github.com/msgpack/msgpack-php/archive/msgpack-2.0.3.tar.gz
Unzip
tar -zxvf msgpack-2.0.3.tar.gz cd msgpack-php-msgpack-2.0.3/
Viewphpize
File path
$ whereis phpize phpize: /usr/local/php-7.2.9/bin/phpize
Compile from source code
$./configure $make && make install
Modify configuration file
sudo vim /usr/local/php-7.2.9/etc/php.ini // 增加以下扩展 extension=msgpack.so
Restartphp-fpm
Check whether the installation is successful
sudo systemctl restart php-fpm.service
Official simple case msgpack-test.php
<?php $data = array(0=>1,1=>2,2=>3); $msg = msgpack_pack($data); var_dump($data); echo '----------------'; var_dump($msg); $data = msgpack_unpack($msg); var_dump($data);
Running results
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ----------------string(4) "" array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
For more PHP related knowledge, please visit php tutorial!
The above is the detailed content of About how to compile and install msgpack-php. For more information, please follow other related articles on the PHP Chinese website!