Skip to content

Commit

Permalink
Merge in upstream changes from master branch of php-memcached GitHub …
Browse files Browse the repository at this point in the history
…project (3.0.1 release)
  • Loading branch information
malyeyev-AMZN committed Feb 8, 2017
2 parents 4a3a80b + 71f20e1 commit b1300bf
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 74 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
- LIBMEMCACHED_VERSION=1.0.18 # Debian Jessie / Ubuntu Xenial
- LIBMEMCACHED_VERSION=1.0.16 # RHEL / CentOS 7
- LIBMEMCACHED_VERSION=1.0.8 # Debian Wheezy / Ubuntu Trusty
- LIBMEMCACHED_VERSION=1.0.2 # Ancient

addons:
apt:
Expand All @@ -22,11 +23,12 @@ addons:
- libevent-dev

before_script:
- sudo apt-get purge -qq '^memcached*' '^libmemcached*'
- ./.travis/travis.sh before_script $LIBMEMCACHED_VERSION

script:
- ./.travis/travis.sh script $LIBMEMCACHED_VERSION

cache:
directories:
- $HOME/cache
- $HOME/cache
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
memcached extension changelog

Version 3.0.1 (2017-02-07)
-------------

* Add API entries for flushBuffers() and getAllKeys() (#316)
* Ignore specific errors from memcached_dump for getAllKeys() with newer memcached servers (#315)
* Fix compiling with memcached binary protocol enabled (#312)
* Restore php_libmemcached_compat with workaround for missing memcached_exists (#314)
* Travis CI purge old versions of memcached and libmemcached (#309)

Version 3.0.0 (2017-01-27)
--------------------------
* Support for PHP 7.0 and PHP 7.1
Expand Down
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ if test "$PHP_MEMCACHED" != "no"; then
AC_DEFINE(HAVE_MEMCACHED_EXIST, [1], [Whether memcached_exist is defined])
fi

PHP_MEMCACHED_FILES="php_memcached.c g_fmt.c"
PHP_MEMCACHED_FILES="php_memcached.c php_libmemcached_compat.c g_fmt.c"

if test "$PHP_SYSTEM_FASTLZ" != "no"; then
AC_CHECK_HEADERS([fastlz.h], [ac_cv_have_fastlz="yes"], [ac_cv_have_fastlz="no"])
Expand Down
4 changes: 4 additions & 0 deletions memcached-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ public function getLastDisconnectedServer( ) {}

public function flush( $delay = 0 ) {}

public function flushBuffers( ) {}

public function getStats( $type = null ) {}

public function getAllKeys( ) {}

public function getVersion( ) {}

Expand Down
69 changes: 47 additions & 22 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>[email protected]</email>
<active>yes</active>
</lead>
<date>2017-01-27</date>
<date>2017-02-07</date>
<version>
<release>3.0.0</release>
<release>3.0.1</release>
<api>3.0.0</api>
</version>
<stability>
Expand All @@ -36,26 +36,12 @@ PHP7 release of memcached extension. Note that support for libmemcached 0.x seri
and the oldest actively tested version is 1.0.2. It is highly recommended to use version 1.0.18 of
libmemcached.

API
* The method signature of get, getByKey, getMulti, and getMultiByKey changed.
* get* and getMulti* commands no longer take cas or user flags parameters.
* get* and getMulti* commands now take the Memcached::GET_EXTENDED flag to retrieve user flags and cas tokens.
* Fixes getStats command to return all stats from all servers
* Fixes allKeys command behaviour
* Fixes error where cache callback for get command was not setting expiration time properly
* Added server type to server list
* Remove use_sasl ini-variable and initialise sasl as needed
* CAS tokens are returned as integers and they overflow to strings as needed

Session handler
* The session memcached protocol config name was changed, and the default protocol was changed from text to binary protocol. If your memcached setup does not support the binary protocol(e.g. if using twemproxy), then set memcached.sess_binary_protocol = Off. (Previously called memcached.sess_binary)
* Session lock algorithm updated (new ini-values memcached.sess_lock_wait_min, memcached.sess_lock_wait_max and memcached.sess_lock_retries)
* Session extension uses PHP allocators (still some work to do on the rest of the extension)
* Ini-values take effect during session_start or session_regenerate_id
* Fixes crash with session_regenerate_id (work-around for PHP bug)

Tests
* Fix several problematic tests
Fixes
* Add API entries for flushBuffers() and getAllKeys() (#316)
* Ignore specific errors from memcached_dump for getAllKeys() with newer memcached servers (#315)
* Fix compiling with memcached binary protocol enabled (#312)
* Restore php_libmemcached_compat with workaround for missing memcached_exists (#314)
* Travis CI purge old versions of memcached and libmemcached (#309)
</notes>
<contents>
<dir name="/">
Expand All @@ -73,6 +59,8 @@ Tests
<file role='src' name='php_memcached_private.h'/>
<file role='src' name='php_memcached_session.c'/>
<file role='src' name='php_memcached_session.h'/>
<file role='src' name='php_libmemcached_compat.h'/>
<file role='src' name='php_libmemcached_compat.c'/>
<file role='src' name='php_memcached_server.h'/>
<file role='src' name='php_memcached_server.c'/>
<file role='src' name='g_fmt.c'/>
Expand Down Expand Up @@ -194,6 +182,43 @@ Tests
<configureoption name="with-libmemcached-dir" default="no" prompt="libmemcached directory"/>
</extsrcrelease>
<changelog>
<release>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<version>
<release>3.0.0</release>
<api>3.0.0</api>
</version>
<date>2016-01-27</date>
<notes>
PHP7 release of memcached extension. Note that support for libmemcached 0.x series has been discontinued
and the oldest actively tested version is 1.0.2. It is highly recommended to use version 1.0.18 of
libmemcached.

API
* The method signature of get, getByKey, getMulti, and getMultiByKey changed.
* get* and getMulti* commands no longer take cas or user flags parameters.
* get* and getMulti* commands now take the Memcached::GET_EXTENDED flag to retrieve user flags and cas tokens.
* Fixes getStats command to return all stats from all servers
* Fixes allKeys command behaviour
* Fixes error where cache callback for get command was not setting expiration time properly
* Added server type to server list
* Remove use_sasl ini-variable and initialise sasl as needed
* CAS tokens are returned as integers and they overflow to strings as needed

Session handler
* The session memcached protocol config name was changed, and the default protocol was changed from text to binary protocol. If your memcached setup does not support the binary protocol(e.g. if using tw
* Session lock algorithm updated (new ini-values memcached.sess_lock_wait_min, memcached.sess_lock_wait_max and memcached.sess_lock_retries)
* Session extension uses PHP allocators (still some work to do on the rest of the extension)
* Ini-values take effect during session_start or session_regenerate_id
* Fixes crash with session_regenerate_id (work-around for PHP bug)

Tests
* Fix several problematic tests
</notes>
</release>
<release>
<stability>
<release>alpha</release>
Expand Down
37 changes: 37 additions & 0 deletions php_libmemcached_compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andrei Zmievski <[email protected]> |
+----------------------------------------------------------------------+
*/

#include "php_memcached.h"
#include "php_memcached_private.h"
#include "php_libmemcached_compat.h"

memcached_return php_memcached_exist (memcached_st *memc, zend_string *key)
{
#ifdef HAVE_MEMCACHED_EXIST
return memcached_exist (memc, key->val, key->len);
#else
memcached_return rc = MEMCACHED_SUCCESS;
uint32_t flags = 0;
size_t value_length = 0;
char *value = NULL;

value = memcached_get (memc, key->val, key->len, &value_length, &flags, &rc);
if (value) {
free (value);
}
return rc;
#endif
}
31 changes: 31 additions & 0 deletions php_libmemcached_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andrei Zmievski <[email protected]> |
+----------------------------------------------------------------------+
*/

#ifndef PHP_LIBMEMCACHED_COMPAT
#define PHP_LIBMEMCACHED_COMPAT

/* this is the version(s) we support */
#include <libmemcached/memcached.h>

memcached_return php_memcached_exist (memcached_st *memc, zend_string *key);

#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000017
typedef const memcached_instance_st * php_memcached_instance_st;
#else
typedef memcached_server_instance_st php_memcached_instance_st;
#endif

#endif
34 changes: 12 additions & 22 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
# include "ext/msgpack/php_msgpack.h"
#endif

#ifdef ZTS
#define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc.v)
#else
#define MEMC_G(v) (php_memcached_globals.memc.v)
#endif

static int le_memc;

static int php_memc_list_entry(void) {
Expand Down Expand Up @@ -238,24 +232,14 @@ static inline php_memc_server_t *php_memc_server_fetch_object(zend_object *obj)
}
#define Z_MEMC_SERVER_P(zv) php_memc_server_fetch_object(Z_OBJ_P(zv))

#ifdef ZTS
#define MEMC_SERVER_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, server.v)
#else
#define MEMC_SERVER_G(v) (php_memcached_globals.server.v)
#endif
static zend_object_handlers memcached_server_object_handlers;
static zend_class_entry *memcached_server_ce = NULL;
#endif

static zend_class_entry *memcached_ce = NULL;

static zend_class_entry *memcached_exception_ce = NULL;

static zend_object_handlers memcached_object_handlers;

#ifdef HAVE_MEMCACHED_PROTOCOL
static zend_object_handlers memcached_server_object_handlers;
static zend_class_entry *memcached_server_ce = NULL;
#endif

#ifdef HAVE_SPL
static zend_class_entry *spl_ce_RuntimeException = NULL;
#endif
Expand Down Expand Up @@ -2741,7 +2725,15 @@ PHP_METHOD(Memcached, getAllKeys)
array_init(return_value);

rc = memcached_dump(intern->memc, callback, return_value, 1);
if (s_memc_status_handle_result_code(intern, rc) == FAILURE) {

/* Ignore two errors. libmemcached has a hardcoded loop of 200 slab
* classes that matches memcached < 1.4.24, at which version the server
* has only 63 slabs and throws an error when requesting the 64th slab.
*
* In multi-server some non-deterministic number of elements will be dropped.
*/
if (rc != MEMCACHED_CLIENT_ERROR && rc != MEMCACHED_SERVER_ERROR
&& s_memc_status_handle_result_code(intern, rc) == FAILURE) {
zval_dtor(return_value);
RETURN_FALSE;
}
Expand Down Expand Up @@ -3644,7 +3636,7 @@ PHP_METHOD(MemcachedServer, run)
static
PHP_METHOD(MemcachedServer, on)
{
long event;
zend_long event;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache;
zend_bool rc = 0;
Expand Down Expand Up @@ -4022,7 +4014,6 @@ static zend_function_entry memcached_class_methods[] = {
MEMC_ME(getLastErrorMessage, arginfo_getLastErrorMessage)
MEMC_ME(getLastErrorCode, arginfo_getLastErrorCode)
MEMC_ME(getLastErrorErrno, arginfo_getLastErrorErrno)

MEMC_ME(getLastDisconnectedServer, arginfo_getLastDisconnectedServer)

MEMC_ME(getStats, arginfo_getStats)
Expand Down Expand Up @@ -4218,7 +4209,6 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_MODULA, MEMCACHED_DISTRIBUTION_MODULA);
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_CONSISTENT, MEMCACHED_DISTRIBUTION_CONSISTENT);
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_VIRTUAL_BUCKET, MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET);

REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_COMPATIBLE, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_HASH, MEMCACHED_BEHAVIOR_KETAMA_HASH);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_TCP_KEEPALIVE, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE);
Expand Down
10 changes: 9 additions & 1 deletion php_memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# include "config.h"
#endif

#define PHP_MEMCACHED_VERSION "3.0.0"
#define PHP_MEMCACHED_VERSION "3.0.1"

#if defined(PHP_WIN32) && defined(MEMCACHED_EXPORTS)
#define PHP_MEMCACHED_API __declspec(dllexport)
Expand All @@ -42,6 +42,14 @@ PHP_MEMCACHED_API zend_class_entry *php_memc_get_exception_base(int root);
extern zend_module_entry memcached_module_entry;
#define phpext_memcached_ptr &memcached_module_entry

#ifdef ZTS
#define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc.v)
#define MEMC_SERVER_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, server.v)
#else
#define MEMC_G(v) (php_memcached_globals.memc.v)
#define MEMC_SERVER_G(v) (php_memcached_globals.server.v)
#endif

#endif /* PHP_MEMCACHED_H */

/*
Expand Down
10 changes: 3 additions & 7 deletions php_memcached_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@
# include "config.h"
#endif

#include <libmemcached/memcached.h>

#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000017
typedef const memcached_instance_st * php_memcached_instance_st;
#else
typedef memcached_server_instance_st php_memcached_instance_st;
#endif
#include "php_libmemcached_compat.h"

#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -214,6 +208,8 @@ PHP_MINFO_FUNCTION(memcached);

char *php_memc_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);

memcached_return php_memcached_exist (memcached_st *memc, zend_string *key);

zend_bool php_memc_init_sasl_if_needed();

#endif /* PHP_MEMCACHED_PRIVATE_H */
Expand Down
Loading

0 comments on commit b1300bf

Please sign in to comment.