Giter Club home page Giter Club logo

msgpack-php's Introduction

MessagePack PHP functions

The purpose of this project is to implement MessagePack serialization using only PHP. It aims to work even on very old versions of PHP, such as found in many long-term support server distros, while supporting the modern str8/bin8/bin16/bin32 additions to msgpack.

Additions

  • Supports decoding and encoding str8 and bin8/16/32 types.
  • By analogy to the python implementation, msgpack_unpackb accepts $raw parameter determining handling of str types (default: $raw=True).
  • By analogy to the python implementation, msgpack_packb accepts $use_bin_type parameter determining use of bin types (default: $use_bin_type=False).
  • PHP has no concept of bytes vs unicode strings, so msgpack_packb also accepts $force_str_as_bin parameter forcing the use of bin types event for strings that are valid utf-8.

Caveats

  • Only msgpack_packb() and msgpack_unpackb() are defined.
  • It's only tested on little endian architecture, but should work on big endian as well.
  • It uses is_x() to select the type, do your casts before using the functions
  • Unlike the official lib you can't pack objects. Feel free to submit a pull request to add this functionality.
  • It will always pack integers into the least amount of bits possible, and will prefer unsigned.
  • It does not support ext/fixext types.

Benchmark

Based on msgpack/php/benchmark.php

As you can see the pure PHP implementation (msgpack-php) is quite slow compared with the great php-extension msgpack has created. However when msgpack-php is compiled using HipHop (msgpack-hphp) the performance difference is much less, with msgpack-hphp even beating msgpack in this particular benchmark a few places, perhaps due to the fact that the benchmark itself is compiled with HipHop as well.

The timing values are average seconds sampled 10 times with 10.000 iterations each. Percentages are relative to normal php serialize() (not HipHop's version).

[integer   ]       default          json      igbinary       msgpack   msgpack-php   msgpack-hphp
status     :           OK           OK           OK           OK           OK          OK
serialize  : 0.0105 (100%) 0.0090 ( 85%) 0.0089 ( 84%) 0.0093 ( 88%) 0.0550 ( 523%) 0.0051 ( 57%)
unserialize: 0.0089 (100%) 0.0119 (134%) 0.0088 ( 99%) 0.0090 (101%) 0.0985 (1110%) 0.0208 (234%)
size       :     12 (100%)      9 ( 75%)      9 ( 75%)      5 ( 41%)      5 (  41%)      5 ( 41%)

[double    ]       default          json      igbinary       msgpack   msgpack-php   msgpack-hphp
status     :           OK           OK           OK           OK           OK          OK
serialize  : 0.0323 (100%) 0.0132 ( 40%) 0.0092 ( 28%) 0.0094 ( 28%) 0.0740 (229%)  0.0074 ( 23%)
unserialize: 0.0221 (100%) 0.0124 ( 56%) 0.0085 ( 38%) 0.0089 ( 40%) 0.1151 (521%)  0.0217 ( 98%)
size       :     54 (100%)     15 ( 27%)     13 ( 24%)      9 ( 16%)      9 ( 16%)       9 ( 16%)

[string    ]       default          json      igbinary       msgpack   msgpack-php   msgpack-hphp
status     :           OK           OK           OK           OK           OK          OK
serialize  : 0.0104 (100%) 0.0123 (118%) 0.0092 ( 88%) 0.0096 ( 91%) 0.0728 ( 700%) 0.0067 ( 64%)
unserialize: 0.0095 (100%) 0.0153 (160%) 0.0093 ( 97%) 0.0097 (101%) 0.1469 (1543%) 0.0301 (316%)
size       :     40 (100%)     34 ( 85%)     38 ( 95%)     35 ( 87%)     35 (  87%)     35 ( 87%)

[array     ]       default          json      igbinary       msgpack   msgpack-php   msgpack-hphp
status     :           OK           OK           OK           OK           OK          OK
serialize  : 0.0183 (100%) 0.0297 (162%) 0.0222 (121%) 0.0134 ( 73%) 0.5567 (3042%) 0.0432 (236%)
unserialize: 0.0174 (100%) 0.0363 (207%) 0.0171 ( 98%) 0.0170 ( 97%) 0.7823 (4483%) 0.1665 (957%)
size       :    226 (100%)    176 ( 77%)    186 ( 82%)    176 ( 77%)    176 (  77%)    176 ( 77%)

[array     ]       default          json      igbinary       msgpack    msgpack-php   msgpack-hphp
status     :           OK           OK           OK           OK           OK           OK
serialize  : 0.0199 (100%) 0.0481 (242%) 0.0306 (153%) 0.0148 ( 74%) 0.8513 (4285%) 0.0763 ( 383%)
unserialize: 0.0231 (100%) 0.0583 (252%) 0.0202 ( 87%) 0.0248 (107%) 1.4168 (6134%) 0.3156 (1366%)
size       :    406 (100%)    351 ( 86%)    346 ( 85%)    351 ( 86%)    351 (  86%)    351 (  86%)

msgpack-php's People

Contributors

cypres avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.