-
Notifications
You must be signed in to change notification settings - Fork 326
Added msgpack serializer support #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2ac3a9c
6fa359d
82264b4
8982f17
ac4a9a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,10 @@ typedef unsigned long int uint32_t; | |
# include "ext/igbinary/igbinary.h" | ||
#endif | ||
|
||
#ifdef HAVE_MEMCACHED_MSGPACK | ||
# include "ext/msgpack/php_msgpack.h" | ||
#endif | ||
|
||
/* | ||
* This is needed because PHP 5.3.[01] does not install JSON_parser.h by default. This | ||
* constant will move into php_json.h in the future anyway. | ||
|
@@ -124,6 +128,7 @@ typedef unsigned long int uint32_t; | |
#define MEMC_VAL_IS_SERIALIZED 4 | ||
#define MEMC_VAL_IS_IGBINARY 5 | ||
#define MEMC_VAL_IS_JSON 6 | ||
#define MEMC_VAL_IS_MSGPACK 7 | ||
|
||
#define MEMC_VAL_COMPRESSED (1<<4) | ||
#define MEMC_VAL_COMPRESSION_ZLIB (1<<5) | ||
|
@@ -264,7 +269,7 @@ static PHP_INI_MH(OnUpdateSerializer) | |
MEMC_G(serializer) = SERIALIZER_DEFAULT; | ||
} else if (!strcmp(new_value, "php")) { | ||
MEMC_G(serializer) = SERIALIZER_PHP; | ||
#ifdef HAVE_MEMCACHE_IGBINARY | ||
#ifdef HAVE_MEMCACHED_IGBINARY | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's where the existing typo disabled igbinary even if you had it configured, I believe. |
||
} else if (!strcmp(new_value, "igbinary")) { | ||
MEMC_G(serializer) = SERIALIZER_IGBINARY; | ||
#endif // IGBINARY | ||
|
@@ -274,6 +279,10 @@ static PHP_INI_MH(OnUpdateSerializer) | |
} else if (!strcmp(new_value, "json_array")) { | ||
MEMC_G(serializer) = SERIALIZER_JSON_ARRAY; | ||
#endif // JSON | ||
#ifdef HAVE_MEMCACHED_MSGPACK | ||
} else if (!strcmp(new_value, "msgpack")) { | ||
MEMC_G(serializer) = SERIALIZER_MSGPACK; | ||
#endif // msgpack | ||
} else { | ||
return FAILURE; | ||
} | ||
|
@@ -2305,6 +2314,12 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML | |
} else if (Z_LVAL_P(value) == SERIALIZER_JSON_ARRAY) { | ||
m_obj->serializer = SERIALIZER_JSON_ARRAY; | ||
} else | ||
#endif | ||
/* msgpack serializer */ | ||
#ifdef HAVE_MEMCACHED_MSGPACK | ||
if (Z_LVAL_P(value) == SERIALIZER_MSGPACK) { | ||
m_obj->serializer = SERIALIZER_MSGPACK; | ||
} else | ||
#endif | ||
/* php serializer */ | ||
if (Z_LVAL_P(value) == SERIALIZER_PHP) { | ||
|
@@ -2787,6 +2802,20 @@ static char *php_memc_zval_to_payload(zval *value, size_t *payload_len, uint32_t | |
MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_JSON); | ||
break; | ||
} | ||
#endif | ||
#ifdef HAVE_MEMCACHED_MSGPACK | ||
case SERIALIZER_MSGPACK: | ||
php_msgpack_serialize(&buf, value TSRMLS_CC); | ||
if(!buf.c) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spaces for indentation? |
||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not serialize value with msgpack"); | ||
smart_str_free(&buf); | ||
return NULL; | ||
} | ||
p = buf.c; | ||
l = buf.len; | ||
buf_used = 1; | ||
MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_MSGPACK); | ||
break; | ||
#endif | ||
default: | ||
{ | ||
|
@@ -3019,6 +3048,15 @@ static int php_memc_zval_from_payload(zval *value, char *payload, size_t payload | |
#endif | ||
break; | ||
|
||
case MEMC_VAL_IS_MSGPACK: | ||
#ifdef HAVE_MEMCACHED_MSGPACK | ||
php_msgpack_unserialize(value, payload, payload_len TSRMLS_CC); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation? |
||
#else | ||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not unserialize value, no msgpack support"); | ||
goto my_error; | ||
#endif | ||
break; | ||
|
||
default: | ||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unknown payload type"); | ||
goto my_error; | ||
|
@@ -3603,6 +3641,9 @@ static const zend_module_dep memcached_deps[] = { | |
#ifdef HAVE_MEMCACHED_IGBINARY | ||
ZEND_MOD_REQUIRED("igbinary") | ||
#endif | ||
#ifdef HAVE_MEMCACHED_MSGPACK | ||
ZEND_MOD_REQUIRED("msgpack") | ||
#endif | ||
#ifdef HAVE_SPL | ||
ZEND_MOD_REQUIRED("spl") | ||
#endif | ||
|
@@ -3668,6 +3709,15 @@ static void php_memc_register_constants(INIT_FUNC_ARGS) | |
REGISTER_MEMC_CLASS_CONST_LONG(HAVE_JSON, 0); | ||
#endif | ||
|
||
/* | ||
* Indicate whether msgpack serializer is available | ||
*/ | ||
#ifdef HAVE_MEMCACHED_MSGPACK | ||
REGISTER_MEMC_CLASS_CONST_LONG(HAVE_MSGPACK, 1); | ||
#else | ||
REGISTER_MEMC_CLASS_CONST_LONG(HAVE_MSGPACK, 0); | ||
#endif | ||
|
||
#ifdef HAVE_MEMCACHED_SESSION | ||
REGISTER_MEMC_CLASS_CONST_LONG(HAVE_SESSION, 1); | ||
#else | ||
|
@@ -3782,6 +3832,7 @@ static void php_memc_register_constants(INIT_FUNC_ARGS) | |
REGISTER_MEMC_CLASS_CONST_LONG(SERIALIZER_IGBINARY, SERIALIZER_IGBINARY); | ||
REGISTER_MEMC_CLASS_CONST_LONG(SERIALIZER_JSON, SERIALIZER_JSON); | ||
REGISTER_MEMC_CLASS_CONST_LONG(SERIALIZER_JSON_ARRAY, SERIALIZER_JSON_ARRAY); | ||
REGISTER_MEMC_CLASS_CONST_LONG(SERIALIZER_MSGPACK, SERIALIZER_MSGPACK); | ||
|
||
/* | ||
* Compression types | ||
|
@@ -3907,6 +3958,13 @@ PHP_MINFO_FUNCTION(memcached) | |
#else | ||
php_info_print_table_row(2, "json support", "no"); | ||
#endif | ||
|
||
#ifdef HAVE_MEMCACHED_MSGPACK | ||
php_info_print_table_row(2, "msgpack support", "yes"); | ||
#else | ||
php_info_print_table_row(2, "msgpack support", "no"); | ||
#endif | ||
|
||
php_info_print_table_end(); | ||
|
||
DISPLAY_INI_ENTRIES(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
Serialize msgpack | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("memcached")) print "skip"; | ||
if (!extension_loaded('msgpack')) echo "skip no msgpack loaded"; | ||
if (!Memcached::HAVE_MSGPACK) echo "skip msgpack support not enabled"; | ||
?> | ||
--REDIRECTTEST-- | ||
|
||
$path = implode(DIRECTORY_SEPARATOR, array('tests', 'experimental', 'serializer')); | ||
|
||
return array( | ||
'TESTS' => $path, | ||
'ENV' => array('TEST_MEMC_SERIALIZER' => 'Memcached::SERIALIZER_MSGPACK'), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need to double-check all the use cases for serialization, make sure msgpack handles them well. I seem to recall some bumps using JSON encoding certain types of objects (maybe just ones with binary contents?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write some tests for the use-cases?