Skip to content

Commit

Permalink
php: version 0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
advect committed Dec 27, 2010
1 parent 303ab32 commit 293ff79
Show file tree
Hide file tree
Showing 76 changed files with 6,531 additions and 354 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
msgpack extension changelog

Version 0.3.3
-------------
* Update msgpack header files.
* Fix unpack internal processing.

Version 0.3.2
-------------
* Version PHP 5 or newer.

Version 0.3.1
-------------
* Fix class MessagePackUnpacker.
Expand Down
67 changes: 29 additions & 38 deletions benchmark.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
require_once 'Benchmark/Timer.php';

$loop = 10000;
$retry = 10;
$value_display = false;
Expand Down Expand Up @@ -87,24 +85,23 @@
//default (serialize)
$pack = null;
$unpack = null;
$t = new Benchmark_Timer;
$t->start();

$start = microtime(true);
for ($i = 0; $i < $loop; $i++)
{
$pack = serialize($value);
}
$t->setMarker('serialize');
$end = microtime(true);
$serialize_pack += ($end - $start);

$start = microtime(true);
for ($i = 0; $i < $loop; $i++)
{
$unpack = unserialize($pack);
}
$t->stop();
//$t->display();
$profiling = $t->getProfiling();
unset($t);
$end = microtime(true);
$serialize_unpack += ($end - $start);

$serialize_pack += $profiling[1]['diff'];
$serialize_unpack += $profiling[2]['diff'];
$serialize_size += strlen($pack);
if ($unpack === $value ||
(is_object($value) && $unpack == $value))
Expand All @@ -120,24 +117,22 @@
{
$opt = true;
}
$t = new Benchmark_Timer;
$t->start();
$start = microtime(true);
for ($i = 0; $i < $loop; $i++)
{
$pack = json_encode($value);
}
$t->setMarker('json_encode');
$end = microtime(true);
$json_pack += ($end - $start);

$start = microtime(true);
for ($i = 0; $i < $loop; $i++)
{
$unpack = json_decode($pack, $opt);
}
$t->stop();
//$t->display();
$profiling = $t->getProfiling();
unset($t);
$end = microtime(true);
$json_unpack += ($end - $start);

$json_pack += $profiling[1]['diff'];
$json_unpack += $profiling[2]['diff'];
$json_size += strlen($pack);
if ($unpack === $value ||
(is_object($value) && $unpack == $value) ||
Expand All @@ -153,24 +148,22 @@
{
$pack = null;
$unpack = null;
$t = new Benchmark_Timer;
$t->start();
$start = microtime(true);
for ($i = 0; $i < $loop; $i++)
{
$pack = igbinary_serialize($value);
}
$t->setMarker('igbinary_serialize');
$end = microtime(true);
$igbinary_pack += ($end - $start);

$start = microtime(true);
for ($i = 0; $i < $loop; $i++)
{
$unpack = igbinary_unserialize($pack);
}
$t->stop();
//$t->display();
$profiling = $t->getProfiling();
unset($t);
$end = microtime(true);
$igbinary_unpack += ($end - $start);

$igbinary_pack += $profiling[1]['diff'];
$igbinary_unpack += $profiling[2]['diff'];
$igbinary_size += strlen($pack);
if ($unpack === $value ||
(is_object($value) && $unpack == $value))
Expand All @@ -182,24 +175,22 @@
//msgpack
$pack = null;
$unpack = null;
$t = new Benchmark_Timer;
$t->start();
$start = microtime(true);
for ($i = 0; $i < $loop; $i++)
{
$pack = msgpack_serialize($value);
}
$t->setMarker('msgpack_serialize');
$end = microtime(true);
$msgpack_pack += ($end - $start);

$start = microtime(true);
for ($i = 0; $i < $loop; $i++)
{
$unpack = msgpack_unserialize($pack);
}
$t->stop();
//$t->display();
$profiling = $t->getProfiling();
unset($t);
$end = microtime(true);
$msgpack_unpack += ($end - $start);

$msgpack_pack += $profiling[1]['diff'];
$msgpack_unpack += $profiling[2]['diff'];
$msgpack_size += strlen($pack);
if ($unpack === $value ||
(is_object($value) && $unpack == $value))
Expand Down
13 changes: 9 additions & 4 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ dnl Check PHP version:

AC_MSG_CHECKING(PHP version)
AC_TRY_COMPILE([#include "php/main/php_version.h"], [
#if PHP_MAJOR_VERSION < 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 2)
#error this extension requires at least PHP version 5.2.0
#if PHP_MAJOR_VERSION < 5
#error this extension requires at least PHP version 5 or newer
#endif
],
[AC_MSG_RESULT(ok)],
[AC_MSG_ERROR([need at least PHP 5.2.0])])
[AC_MSG_ERROR([need at least PHP 5 or newer])])

dnl If your extension references something external, use with:

Expand All @@ -24,5 +24,10 @@ Make sure that the comment is aligned:
if test "$PHP_MSGPACK" != "no"; then
PHP_NEW_EXTENSION(msgpack, msgpack.c msgpack_pack.c msgpack_unpack.c msgpack_class.c, $ext_shared)

PHP_INSTALL_HEADERS([ext/msgpack], [php_msgpack.h])
ifdef([PHP_INSTALL_HEADERS],
[
PHP_INSTALL_HEADERS([ext/msgpack], [php_msgpack.h])
], [
PHP_ADD_MAKEFILE_FRAGMENT
])
fi
78 changes: 49 additions & 29 deletions msgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ static ZEND_MINIT_FUNCTION(msgpack)

msgpack_init_class();

#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 1)
REGISTER_LONG_CONSTANT(
"MESSAGEPACK_OPT_PHPONLY", MSGPACK_CLASS_OPT_PHPONLY,
CONST_CS | CONST_PERSISTENT);
#endif

return SUCCESS;
}

Expand Down Expand Up @@ -164,33 +170,41 @@ PS_SERIALIZER_DECODE_FUNC(msgpack)

msgpack_unserialize_var_init(&var_hash);

(&mp)->user.retval = (zval *)tmp;
(&mp)->user.var_hash = (php_unserialize_data_t *)&var_hash;
mp.user.retval = (zval *)tmp;
mp.user.var_hash = (php_unserialize_data_t *)&var_hash;

ret = template_execute(&mp, (char *)val, (size_t)vallen, &off);

msgpack_unserialize_var_destroy(&var_hash);
if (ret == MSGPACK_UNPACK_EXTRA_BYTES || ret == MSGPACK_UNPACK_SUCCESS)
{
msgpack_unserialize_var_destroy(&var_hash, 0);

tmp_hash = HASH_OF(tmp);
tmp_hash = HASH_OF(tmp);

zend_hash_internal_pointer_reset_ex(tmp_hash, &tmp_hash_pos);
while (zend_hash_get_current_data_ex(
tmp_hash, (void *)&value, &tmp_hash_pos) == SUCCESS)
{
ret = zend_hash_get_current_key_ex(
tmp_hash, &key_str, &key_len, &key_long, 0, &tmp_hash_pos);
switch (ret)
zend_hash_internal_pointer_reset_ex(tmp_hash, &tmp_hash_pos);

while (zend_hash_get_current_data_ex(
tmp_hash, (void *)&value, &tmp_hash_pos) == SUCCESS)
{
case HASH_KEY_IS_LONG:
/* ??? */
break;
case HASH_KEY_IS_STRING:
php_set_session_var(
key_str, key_len - 1, *value, NULL TSRMLS_CC);
php_add_session_var(key_str, key_len - 1 TSRMLS_CC);
break;
ret = zend_hash_get_current_key_ex(
tmp_hash, &key_str, &key_len, &key_long, 0, &tmp_hash_pos);
switch (ret)
{
case HASH_KEY_IS_LONG:
/* ??? */
break;
case HASH_KEY_IS_STRING:
php_set_session_var(
key_str, key_len - 1, *value, NULL TSRMLS_CC);
php_add_session_var(key_str, key_len - 1 TSRMLS_CC);
break;
}
zend_hash_move_forward_ex(tmp_hash, &tmp_hash_pos);
}
zend_hash_move_forward_ex(tmp_hash, &tmp_hash_pos);
}
else
{
msgpack_unserialize_var_destroy(&var_hash, 1);
}

zval_ptr_dtor(&tmp);
Expand Down Expand Up @@ -226,43 +240,49 @@ PHP_MSGPACK_API void php_msgpack_unserialize(

msgpack_unserialize_var_init(&var_hash);

(&mp)->user.retval = (zval *)return_value;
(&mp)->user.var_hash = (php_unserialize_data_t *)&var_hash;
mp.user.retval = (zval *)return_value;
mp.user.var_hash = (php_unserialize_data_t *)&var_hash;

ret = template_execute(&mp, str, (size_t)str_len, &off);

msgpack_unserialize_var_destroy(&var_hash);

switch (ret)
{
case MSGPACK_UNPACK_PARSE_ERROR:
{
msgpack_unserialize_var_destroy(&var_hash, 1);
if (MSGPACK_G(error_display))
{
zend_error(E_WARNING,
"[msgpack] (php_msgpack_unserialize) Parse error");
"[msgpack] (%s) Parse error", __FUNCTION__);
}
break;
}
case MSGPACK_UNPACK_CONTINUE:
{
msgpack_unserialize_var_destroy(&var_hash, 1);
if (MSGPACK_G(error_display))
{
zend_error(E_WARNING,
"[msgpack] (php_msgpack_unserialize) "
"Insufficient data for unserializing");
"[msgpack] (%s) Insufficient data for unserializing",
__FUNCTION__);
}
break;
}
case MSGPACK_UNPACK_EXTRA_BYTES:
case MSGPACK_UNPACK_SUCCESS:
msgpack_unserialize_var_destroy(&var_hash, 0);
if (off < (size_t)str_len && MSGPACK_G(error_display))
{
zend_error(E_WARNING,
"[msgpack] (php_msgpack_unserialize) Extra bytes");
"[msgpack] (%s) Extra bytes", __FUNCTION__);
}
break;
default:
msgpack_unserialize_var_destroy(&var_hash, 0);
if (MSGPACK_G(error_display))
{
zend_error(E_WARNING,
"[msgpack] (php_msgpack_unserialize) Unknown result");
"[msgpack] (%s) Unknown result", __FUNCTION__);
}
break;
}
Expand Down
Loading

0 comments on commit 293ff79

Please sign in to comment.