Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ php-memcached 3.x:
* Requires libmemcached 1.x or higher.
* Optionally supports igbinary 2.0 or higher.
* Optionally supports msgpack 2.0 or higher.
* Optionally supports phpser 0.9.0 or higher (PHP 8.2 or higher).

php-memcached 2.x:
* Supports PHP 5.2 - 5.6.
Expand All @@ -50,3 +51,32 @@ representation that is interoperable with msgpack implementations for other
languages. When installing php-memcached from source code, the msgpack module
must be installed first so that php-memcached can access its C header files.
Load both modules in your `php.ini` at runtime to begin using msgpack.

[phpser](https://github.com/iliaal/phpser) is a binary serializer for PHP
data structures that can sign what it writes. Build php-memcached with
`--enable-memcached-phpser` after installing phpser, and load phpser before
memcached in your `php.ini` (`extension=phpser` above `extension=memcached`).
Select it with `Memcached::OPT_SERIALIZER => Memcached::SERIALIZER_PHPSER` or
`memcached.serializer = "phpser"`.

Without `phpser.key`, phpser behaves like igbinary: arrays, objects, and null
go through phpser, while strings, integers, floats, and booleans are stored
natively.

When `phpser.key` is set to a key of at least 32 bytes, values are HMAC-signed
for the `memcached` context and verified before decoding, so a client that can
write to the memcached servers cannot make the reader instantiate objects.
In this mode:

* Strings, booleans, null, arrays, and objects are stored as signed phpser
values. Integers and floats stay native, so `increment()` and `decrement()`
keep working.
* Reads accept only signed phpser values that verify, plus native integers and
floats. Any other item, including values written by other serializers, plain
strings, and items created by `increment()` with an initial value, reads back
as `false` with a warning, like a value that fails to unserialize.
* `append()` and `prepend()` are refused with a warning, because they would
break the signature.

A non-empty `phpser.key` shorter than 32 bytes also enables this mode, and
then every phpser write and read fails.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"suggest": {
"ext-igbinary": "igbinary is a faster and more compact binary serializer for PHP data structures.",
"ext-msgpack": "msgpack is a faster and more compact data structure representation that is interoperable with msgpack implementations for other languages."
"ext-msgpack": "msgpack is a faster and more compact data structure representation that is interoperable with msgpack implementations for other languages.",
"ext-phpser": "phpser is a binary serializer for PHP data structures that can sign values with phpser.key."
},
"php-ext": {
"extension-name": "memcached",
Expand All @@ -30,6 +31,10 @@
"name": "enable-memcached-igbinary",
"description": "Enable memcached igbinary serializer support"
},
{
"name": "enable-memcached-phpser",
"description": "Enable memcached phpser serializer support"
},
{
"name": "enable-memcached-json",
"description": "Enable memcached json serializer support"
Expand Down
44 changes: 43 additions & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ PHP_ARG_ENABLE(memcached-session, whether to enable memcached session handler su
PHP_ARG_ENABLE(memcached-igbinary, whether to enable memcached igbinary serializer support,
[ --enable-memcached-igbinary Enable memcached igbinary serializer support], no, no)

PHP_ARG_ENABLE(memcached-phpser, whether to enable memcached phpser serializer support,
[ --enable-memcached-phpser Enable memcached phpser serializer support], no, no)

PHP_ARG_ENABLE(memcached-json, whether to enable memcached json serializer support,
[ --enable-memcached-json Enable memcached json serializer support], no, no)

Expand Down Expand Up @@ -160,6 +163,31 @@ if test "$PHP_MEMCACHED" != "no"; then
fi
fi

if test "$PHP_MEMCACHED_PHPSER" != "no"; then
AC_MSG_CHECKING([for phpser includes])
phpser_inc_path=""

if test -f "$abs_srcdir/include/php/ext/phpser/php_phpser_api.h"; then
phpser_inc_path="$abs_srcdir/include/php"
elif test -f "$abs_srcdir/ext/phpser/php_phpser_api.h"; then
phpser_inc_path="$abs_srcdir"
elif test -f "$phpincludedir/ext/phpser/php_phpser_api.h"; then
phpser_inc_path="$phpincludedir"
else
for i in php php4 php5 php6; do
if test -f "$prefix/include/$i/ext/phpser/php_phpser_api.h"; then
phpser_inc_path="$prefix/include/$i"
fi
done
fi

if test "$phpser_inc_path" = ""; then
AC_MSG_ERROR([Cannot find php_phpser_api.h])
else
AC_MSG_RESULT([$phpser_inc_path])
fi
fi

if test "$PHP_MEMCACHED_MSGPACK" != "no"; then
AC_MSG_CHECKING([for msgpack includes])
msgpack_inc_path=""
Expand Down Expand Up @@ -215,6 +243,20 @@ if test "$PHP_MEMCACHED" != "no"; then
AC_MSG_RESULT([disabled])
fi

AC_MSG_CHECKING([for memcached phpser support])
if test "$PHP_MEMCACHED_PHPSER" != "no"; then
AC_MSG_RESULT([enabled])
AC_DEFINE(HAVE_MEMCACHED_PHPSER,1,[Whether memcache phpser serializer is enabled])
PHPSER_INCLUDES="-I$phpser_inc_path"
ifdef([PHP_ADD_EXTENSION_DEP],
[
PHP_ADD_EXTENSION_DEP(memcached, phpser)
])
else
PHPSER_INCLUDES=""
AC_MSG_RESULT([disabled])
fi

AC_MSG_CHECKING([for memcached msgpack support])
if test "$PHP_MEMCACHED_MSGPACK" != "no"; then
AC_MSG_RESULT([enabled])
Expand Down Expand Up @@ -405,7 +447,7 @@ if test "$PHP_MEMCACHED" != "no"; then
export PKG_CONFIG_PATH="$ORIG_PKG_CONFIG_PATH"
PHP_SUBST(MEMCACHED_SHARED_LIBADD)

PHP_NEW_EXTENSION(memcached, $PHP_MEMCACHED_FILES, $ext_shared,,$SESSION_INCLUDES $IGBINARY_INCLUDES $LIBEVENT_INCLUDES $MSGPACK_INCLUDES)
PHP_NEW_EXTENSION(memcached, $PHP_MEMCACHED_FILES, $ext_shared,,$SESSION_INCLUDES $IGBINARY_INCLUDES $PHPSER_INCLUDES $LIBEVENT_INCLUDES $MSGPACK_INCLUDES)
if test "ac_cv_have_fastlz" != "yes"; then
PHP_ADD_BUILD_DIR($ext_builddir/fastlz, 1)
fi
Expand Down
12 changes: 12 additions & 0 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ARG_ENABLE('memcached', 'libmemcached extension', 'no');

ARG_ENABLE('memcached-session', 'whether to enable memcached session handler support', 'no');
ARG_ENABLE('memcached-igbinary', 'whether to enable memcached igbinary serializer support', 'no');
ARG_ENABLE('memcached-phpser', 'whether to enable memcached phpser serializer support', 'no');
ARG_ENABLE('memcached-json', 'whether to enable memcached json serializer support', 'no');
ARG_ENABLE('memcached-msgpack', 'whether to enable memcached msgpack serializer support', 'no');

Expand Down Expand Up @@ -36,6 +37,17 @@ if (PHP_MEMCACHED == "yes") {
ERROR("memcached: header 'igbinary.h' not found");
}
}
if (PHP_MEMCACHED_PHPSER != "no"){
AC_DEFINE("HAVE_MEMCACHED_PHPSER",1);
ADD_EXTENSION_DEP("memcached", "phpser", true);
if (!CHECK_HEADER_ADD_INCLUDE("php_phpser_api.h", "CFLAGS_MEMCACHED", configure_module_dirname + "\\..\\phpser")) {
ERROR("memcached: header 'php_phpser_api.h' not found");
}
// php_phpser_api.h selects dllimport only when COMPILE_DL_PHPSER is defined.
if (typeof(PHP_PHPSER_SHARED) != "undefined" && PHP_PHPSER_SHARED) {
ADD_FLAG("CFLAGS_MEMCACHED", "/D COMPILE_DL_PHPSER");
}
}
if (PHP_MEMCACHED_MSGPACK != "no"){
AC_DEFINE("HAVE_MEMCACHED_MSGPACK",1);
ADD_EXTENSION_DEP("memcached", "msgpack", true);
Expand Down
4 changes: 4 additions & 0 deletions memcached-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class Memcached {

const HAVE_MSGPACK;

const HAVE_PHPSER;

const HAVE_ENCODING;

/**
Expand Down Expand Up @@ -127,6 +129,8 @@ class Memcached {

const SERIALIZER_MSGPACK;

const SERIALIZER_PHPSER;

/**
* Compression types
*/
Expand Down
4 changes: 3 additions & 1 deletion memcached.ini
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
;memcached.compression_threshold = 2000

; Set the default serializer for new memcached objects.
; valid values are: php, igbinary, json, json_array, msgpack
; valid values are: php, igbinary, json, json_array, msgpack, phpser
;
; json - standard php JSON encoding. This serializer
; is fast and compact but only works on UTF-8
Expand All @@ -122,6 +122,8 @@
; php - the standard php serializer
; igbinary - a binary serializer
; msgpack - a cross-language binary serializer
; phpser - a binary serializer; with phpser.key set, values are signed and
; only signed values, integers, and floats are read back
;
; The default is igbinary if available, then msgpack if available, then php otherwise.
;memcached.serializer = "igbinary"
Expand Down
14 changes: 14 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file role='test' name='types_msgpack_multi.phpt'/>
<file role='test' name='types_php.phpt'/>
<file role='test' name='types_php_multi.phpt'/>
<file role='test' name='types_phpser.phpt'/>
<file role='test' name='types_phpser_keyed.phpt'/>
<file role='test' name='phpser.inc'/>
<file role='test' name='phpser_keyed.phpt'/>
<file role='test' name='phpser_keyed_attack.phpt'/>
<file role='test' name='phpser_keyed_incr_initial.phpt'/>
<file role='test' name='phpser_keyed_multi.phpt'/>
<file role='test' name='phpser_short_key.phpt'/>
<file role='test' name='phpser_unkeyed.phpt'/>
<file role='test' name='undefined_set.phpt'/>
<file role='test' name='vbucket.phpt'/>
<file role='test' name='vbucket_error_7.phpt'/>
Expand Down Expand Up @@ -206,6 +215,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
<name>msgpack</name>
<min>2.0</min>
</extension>
<extension>
<name>phpser</name>
<min>0.9.0</min>
</extension>
</optional>
</dependencies>
<providesextension>memcached</providesextension>
Expand All @@ -216,6 +229,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<configureoption name="with-zstd" prompt="use system zstd library" default="no"/>
<configureoption name="enable-memcached-igbinary" prompt="enable igbinary serializer" default="no"/>
<configureoption name="enable-memcached-msgpack" prompt="enable msgpack serializer" default="no"/>
<configureoption name="enable-memcached-phpser" prompt="enable phpser serializer" default="no"/>
<configureoption name="enable-memcached-json" prompt="enable json serializer" default="no"/>
<configureoption name="enable-memcached-protocol" prompt="enable server protocol" default="no"/>
<configureoption name="enable-memcached-sasl" prompt="enable sasl" default="yes"/>
Expand Down
Loading
Loading