• Stars
    star
    774
  • Rank 58,703 (Top 2 %)
  • Language
    PHP
  • License
    BSD 3-Clause "New...
  • Created about 12 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

msgpack.org[PHP]

Msgpack for PHP

Build Status

This extension provides an API for communicating with MessagePack serialization.

MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages just like JSON. But unlike JSON, it is very fast and small.

Requirement

  • PHP 7.0 +

Install

Install from PECL

Msgpack is a PECL extension, thus you can simply install it by:

pecl install msgpack

Compile Msgpack from source

/path/to/phpize
./configure --with-php-config=/path/to/php-config
make && make install

Example

<?php
$data = array(0 => 1, 1 => 2, 2 => 3);
$msg = msgpack_pack($data);
$data = msgpack_unpack($msg);

Advanced Example

<?php
$data = array(0 => 1, 1 => 2, 2 => 3);
$packer = new \MessagePack(false);
// ^ same as $packer->setOption(\MessagePack::OPT_PHPONLY, false);
$packed = $packer->pack($data);

$unpacker = new \MessagePackUnpacker(false);
// ^ same as $unpacker->setOption(\MessagePack::OPT_PHPONLY, false);
$unpacker->feed($packed);
$unpacker->execute();
$unpacked = $unpacker->data();
$unpacker->reset();

Advanced Streaming Example

<?php
$data1 = array(0 => 1, 1 => 2, 2 => 3);
$data2 = array("a" => 1, "b" => 2, "c" => 3);

$packer = new \MessagePack(false);
$packed1 = $packer->pack($data1);
$packed2 = $packer->pack($data2);

$unpacker = new \MessagePackUnpacker(false);
$buffer = "";
$nread = 0;

//Simulating streaming data :)
$buffer .= $packed1;
$buffer .= $packed2;

while(true) {
   if($unpacker->execute($buffer, $nread)) {
       $msg = $unpacker->data();

       var_dump($msg);

       $unpacker->reset();
       $buffer = substr($buffer, $nread);
       $nread = 0;
       if(!empty($buffer)) {
            continue;
       }
   }
   break;
}

Resources

More Repositories

1

msgpack

MessagePack is an extremely efficient object serialization library. It's like JSON, but very fast and small.
6,905
star
2

msgpack-c

MessagePack implementation for C and C++ / msgpack.org[C/C++]
2,991
star
3

msgpack-python

MessagePack serializer implementation for Python msgpack.org[Python]
Python
1,883
star
4

msgpack-java

MessagePack serializer implementation for Java / msgpack.org[Java]
Java
1,403
star
5

msgpack-javascript

@msgpack/msgpack - MessagePack for JavaScript / msgpack.org[JavaScript/TypeScript/ECMA-262]
TypeScript
1,256
star
6

msgpack-cli

MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]
C#
828
star
7

msgpack-ruby

MessagePack implementation for Ruby / msgpack.org[Ruby]
Ruby
759
star
8

msgpack-node

MessagePack implementation for Node.js
JavaScript
311
star
9

msgpack-objectivec

MessagePack serializer implementation for Objective-C / msgpack.org[Objective-C]
C
300
star
10

msgpack-erlang

MessagePack (de)serializer implementation for Erlang / msgpack.org[Erlang]
Erlang
210
star
11

msgpack-go

Go
149
star
12

msgpack-haskell

Haskell implementation of MessagePack / msgpack.org[Haskell]
Haskell
136
star
13

msgpack-d

MessagePack for D / msgpack.org[D]
D
116
star
14

msgpack-scala

MessagePack serializer implementation for Scala / msgpack.org[Scala]
Shell
94
star
15

website

http://msgpack.org/
HTML
57
star
16

msgpack-perl

MessagePack serializer implementation for Perl / msgpack.org[Perl]
C
51
star
17

msgpack-ocaml

MessagePack implementation for OCaml / msgpack.org[OCaml]
OCaml
45
star
18

msgpack-hadoop

MessagePack-Hadoop integration provides an efficient schema-free data representation for Hadoop and Hive.
Java
34
star
19

msgpack-smalltalk

MessagePack serialization library for various Smalltalk dialects / msgpack.org[Smalltalk]
Smalltalk
22
star
20

pickling-msgpack

Msgpack support for Scala pickling object serialization framework.
Scala
7
star
21

custom-types

See this thread: https://github.com/msgpack/msgpack/issues/121
1
star