Skip to content

Commit 7b9ab77

Browse files
committed
Update PHP Extension
1 parent 72a8a05 commit 7b9ab77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+7334
-2097
lines changed

CREDITS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msgpack
1+
msgpack

ChangeLog

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
msgpack extension changelog
2+
3+
Version 0.2.1
4+
-------------
5+
* Fix stream deserializer
6+
7+
Version 0.2.0
8+
-------------
9+
* Add stream deserializer / class MessagePackUnpacker interface
10+
* Add alias functions
11+
* Add class MessagePack interface
12+
13+
Version 0.1.5
14+
-------------
15+
* Add msgpack_pack.c
16+
* Add msgpack_unpack.c
17+
* Update msgpack.c
18+
19+
Version 0.1.4
20+
-------------
21+
* Change broken random data.
22+
* Support PHP 5.2.x version.
23+
24+
Version 0.1.3
25+
-------------
26+
* Fix broken random data.
27+
* Change arrays and objects.
28+
29+
Version 0.1.2
30+
-------------
31+
* Add Serializable class support.
32+
* Fix arrays and objects reference.
33+
34+
Version 0.1.1
35+
-------------
36+
* Add session support.
37+
38+
Version 0.1.0
39+
-------------
40+
* Initial release.

LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2010, advect
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
* Neither the name of the advect nor the names of its contributors
13+
may be used to endorse or promote products derived from this software
14+
without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26+
THE POSSIBILITY OF SUCH DAMAGE.

README

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Description
2+
-----------
3+
This extension provide API for communicating with MessagePack serialization.
4+
5+
MessagePack is a binary-based efficient object serialization library.
6+
It enables to exchange structured objects between many languages like JSON.
7+
But unlike JSON, it is very fast and small.
8+
9+
Resources
10+
---------
11+
* [msgpack](http://msgpack.sourceforge.net/)

benchmark.php

+248
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
<?php
2+
require_once 'Benchmark/Timer.php';
3+
4+
$loop = 10000;
5+
$retry = 10;
6+
$value_display = false;
7+
8+
$types = array(
9+
1, //integer
10+
2, //float
11+
3, //string
12+
4, //array
13+
5, //hash
14+
6, //object
15+
);
16+
17+
foreach ($types as $type)
18+
{
19+
switch ($type)
20+
{
21+
case 1:
22+
//integer
23+
$value = rand();
24+
break;
25+
case 2:
26+
//float
27+
$value = log(rand());
28+
break;
29+
case 3:
30+
//string
31+
$value = md5(rand());
32+
break;
33+
case 4:
34+
//array
35+
$value = array(md5(rand()),
36+
md5(rand()),
37+
md5(rand()),
38+
md5(rand()),
39+
md5(rand()));
40+
break;
41+
case 5:
42+
//hash
43+
$value = array(md5(rand()) => md5(rand()),
44+
md5(rand()) => md5(rand()),
45+
md5(rand()) => md5(rand()),
46+
md5(rand()) => md5(rand()),
47+
md5(rand()) => md5(rand()));
48+
break;
49+
case 6:
50+
//object
51+
$value = new stdClass;
52+
$value->param1 = rand();
53+
$value->param2 = md5(uniqid());
54+
$value->param3 = array(md5(uniqid()));
55+
$value->param4 = array(md5(uniqid()) => md5(uniqid()));
56+
$value->param5 = null;
57+
break;
58+
default:
59+
//null
60+
$value = null;
61+
}
62+
63+
if (!is_numeric($retry) || empty($retry))
64+
{
65+
$retry = 1;
66+
}
67+
68+
$serialize_pack = 0;
69+
$serialize_unpack = 0;
70+
$serialize_size = 0;
71+
$serialize_status = '*NG*';
72+
$json_pack = 0;
73+
$json_unpack = 0;
74+
$json_size = 0;
75+
$json_status = '*NG*';
76+
$igbinary_pack = 0;
77+
$igbinary_unpack = 0;
78+
$igbinary_size = 0;
79+
$igbinary_status = '*NG*';
80+
$msgpack_pack = 0;
81+
$msgpack_unpack = 0;
82+
$msgpack_size = 0;
83+
$msgpack_status = '*NG*';
84+
85+
for ($c = 0; $c < $retry; $c++)
86+
{
87+
//default (serialize)
88+
$pack = null;
89+
$unpack = null;
90+
$t = new Benchmark_Timer;
91+
$t->start();
92+
for ($i = 0; $i < $loop; $i++)
93+
{
94+
$pack = serialize($value);
95+
}
96+
$t->setMarker('serialize');
97+
for ($i = 0; $i < $loop; $i++)
98+
{
99+
$unpack = unserialize($pack);
100+
}
101+
$t->stop();
102+
//$t->display();
103+
$profiling = $t->getProfiling();
104+
unset($t);
105+
106+
$serialize_pack += $profiling[1]['diff'];
107+
$serialize_unpack += $profiling[2]['diff'];
108+
$serialize_size += strlen($pack);
109+
if ($unpack === $value ||
110+
(is_object($value) && $unpack == $value))
111+
{
112+
$serialize_status = 'OK';
113+
}
114+
115+
//json
116+
$pack = null;
117+
$unpack = null;
118+
$opt = false;
119+
if (is_array($value))
120+
{
121+
$opt = true;
122+
}
123+
$t = new Benchmark_Timer;
124+
$t->start();
125+
for ($i = 0; $i < $loop; $i++)
126+
{
127+
$pack = json_encode($value);
128+
}
129+
$t->setMarker('json_encode');
130+
for ($i = 0; $i < $loop; $i++)
131+
{
132+
$unpack = json_decode($pack, $opt);
133+
}
134+
$t->stop();
135+
//$t->display();
136+
$profiling = $t->getProfiling();
137+
unset($t);
138+
139+
$json_pack += $profiling[1]['diff'];
140+
$json_unpack += $profiling[2]['diff'];
141+
$json_size += strlen($pack);
142+
if ($unpack === $value ||
143+
(is_object($value) && $unpack == $value) ||
144+
(is_float($value) &&
145+
number_format($value, 10, '.', '') ===
146+
number_format($unpack, 10, '.', '')))
147+
{
148+
$json_status = 'OK';
149+
}
150+
151+
//igbinary
152+
if (extension_loaded('igbinary'))
153+
{
154+
$pack = null;
155+
$unpack = null;
156+
$t = new Benchmark_Timer;
157+
$t->start();
158+
for ($i = 0; $i < $loop; $i++)
159+
{
160+
$pack = igbinary_serialize($value);
161+
}
162+
$t->setMarker('igbinary_serialize');
163+
for ($i = 0; $i < $loop; $i++)
164+
{
165+
$unpack = igbinary_unserialize($pack);
166+
}
167+
$t->stop();
168+
//$t->display();
169+
$profiling = $t->getProfiling();
170+
unset($t);
171+
172+
$igbinary_pack += $profiling[1]['diff'];
173+
$igbinary_unpack += $profiling[2]['diff'];
174+
$igbinary_size += strlen($pack);
175+
if ($unpack === $value ||
176+
(is_object($value) && $unpack == $value))
177+
{
178+
$igbinary_status = 'OK';
179+
}
180+
}
181+
182+
//msgpack
183+
$pack = null;
184+
$unpack = null;
185+
$t = new Benchmark_Timer;
186+
$t->start();
187+
for ($i = 0; $i < $loop; $i++)
188+
{
189+
$pack = msgpack_serialize($value);
190+
}
191+
$t->setMarker('msgpack_serialize');
192+
for ($i = 0; $i < $loop; $i++)
193+
{
194+
$unpack = msgpack_unserialize($pack);
195+
}
196+
$t->stop();
197+
//$t->display();
198+
$profiling = $t->getProfiling();
199+
unset($t);
200+
201+
$msgpack_pack += $profiling[1]['diff'];
202+
$msgpack_unpack += $profiling[2]['diff'];
203+
$msgpack_size += strlen($pack);
204+
if ($unpack === $value ||
205+
(is_object($value) && $unpack == $value))
206+
{
207+
$msgpack_status = 'OK';
208+
}
209+
}
210+
211+
$serialize_pack /= $retry;
212+
$serialize_unpack /= $retry;
213+
$serialize_size /= $retry;
214+
$json_pack /= $retry;
215+
$json_unpack /= $retry;
216+
$json_size /= $retry;
217+
$igbinary_pack /= $retry;
218+
$igbinary_unpack /= $retry;
219+
$igbinary_size /= $retry;
220+
$msgpack_pack /= $retry;
221+
$msgpack_unpack /= $retry;
222+
$msgpack_size /= $retry;
223+
224+
printf("[%-10s] %13s %13s %13s %13s\n",
225+
gettype($value), 'default', 'json', 'igbinary', 'msgpack');
226+
printf("status : %12s %12s %12s %12s\n",
227+
$serialize_status, $json_status, $igbinary_status, $msgpack_status);
228+
printf("serialize : %.4f (100%%) %.4f (%3d%%) %.4f (%3d%%) %.4f (%3d%%)\n",
229+
$serialize_pack,
230+
$json_pack, ($json_pack / $serialize_pack * 100),
231+
$igbinary_pack, ($igbinary_pack / $serialize_pack * 100),
232+
$msgpack_pack, ($msgpack_pack / $serialize_pack * 100));
233+
printf("unserialize: %.4f (100%%) %.4f (%3d%%) %.4f (%3d%%) %.4f (%3d%%)\n",
234+
$serialize_unpack,
235+
$json_unpack, ($json_unpack / $serialize_unpack * 100),
236+
$igbinary_unpack, ($igbinary_unpack / $serialize_unpack * 100),
237+
$msgpack_unpack, ($msgpack_unpack / $serialize_unpack * 100));
238+
printf("size : %6d (100%%) %6d (%3d%%) %6d (%3d%%) %6d (%3d%%)\n\n",
239+
$serialize_size,
240+
$json_size, ($json_size / $serialize_size * 100),
241+
$igbinary_size, ($igbinary_size / $serialize_size * 100),
242+
$msgpack_size, ($msgpack_size / $serialize_size * 100));
243+
if ($value_display === true)
244+
{
245+
var_dump($value);
246+
echo PHP_EOL;
247+
}
248+
}

0 commit comments

Comments
 (0)