diff --git a/.travis.yml b/.travis.yml index 4e1d2994..4c82f64f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: php php: - 5.5 - - 5.4 - - 5.3 + #- 5.4 + #- 5.3 env: - LIBMEMCACHED_VERSION=1.0.17 - LIBMEMCACHED_VERSION=1.0.16 @@ -10,12 +10,17 @@ env: - LIBMEMCACHED_VERSION=1.0.14 - LIBMEMCACHED_VERSION=1.0.10 - LIBMEMCACHED_VERSION=1.0.8 + - LIBMEMCACHED_VERSION=1.0.7 + - LIBMEMCACHED_VERSION=1.0.6 - LIBMEMCACHED_VERSION=1.0.2 - LIBMEMCACHED_VERSION=0.53 - LIBMEMCACHED_VERSION=0.44 +services: + - memcached # will start memcached + before_script: - - ./travis.sh before_script $LIBMEMCACHED_VERSION + - ./.travis/travis.sh before_script $LIBMEMCACHED_VERSION script: - - ./travis.sh script $LIBMEMCACHED_VERSION + - ./.travis/travis.sh script $LIBMEMCACHED_VERSION diff --git a/.travis/travis.sh b/.travis/travis.sh new file mode 100755 index 00000000..f90cae9f --- /dev/null +++ b/.travis/travis.sh @@ -0,0 +1,250 @@ +#!/bin/bash + +function version_compare() { + DPKG=`which dpkg` + + if [ "x$DPKG" = "x" ]; then + echo "dpkg not found, cannot compare versions" + exit 1 + fi + + $DPKG --compare-versions "$1" "$2" "$3" + return $? +} + +function check_protocol_support() { + version_compare "$LIBMEMCACHED_VERSION" gt 1.0.15 + if [ $? = 0 ]; then + ENABLE_PROTOOCOL=yes + else + ENABLE_PROTOOCOL=no + fi +} + +function check_sasl_support() { + version_compare "$LIBMEMCACHED_VERSION" gt 1.0.15 + if [ $? = 0 ]; then + ENABLE_SASL=yes + else + ENABLE_SASL=no + fi +} + +function validate_package_xml() { + retval=0 + for file in tests/*.phpt; do + grep $(basename $file) package.xml >/dev/null + if [ $? != 0 ]; then + echo "Missing $file from package.xml" + retval=1; + fi + done + return $retval +} + +function install_libmemcached() { + + wget "https://launchpad.net/libmemcached/1.0/${LIBMEMCACHED_VERSION}/+download/libmemcached-${LIBMEMCACHED_VERSION}.tar.gz" -O libmemcached-${LIBMEMCACHED_VERSION}.tar.gz + + tar xvfz libmemcached-${LIBMEMCACHED_VERSION}.tar.gz + pushd "libmemcached-${LIBMEMCACHED_VERSION}" + + local protocol_flag="" + if test "x$ENABLE_PROTOOCOL" = "xyes"; then + protocol_flag="--enable-libmemcachedprotocol" + fi + + ./configure --prefix="$LIBMEMCACHED_PREFIX" $protocol_flag LDFLAGS="-lpthread" + make + make install + popd +} + +function install_igbinary() { + git clone https://github.com/igbinary/igbinary.git + pushd igbinary + phpize + ./configure + make + make install + popd +} + +function install_msgpack() { + git clone https://github.com/msgpack/msgpack-php.git + pushd msgpack-php + phpize + ./configure + make + make install + popd +} + +function install_sasl() { + + wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz -O memcached-1.4.15.tar.gz + tar xfz memcached-1.4.15.tar.gz + + pushd memcached-1.4.15 + ./configure --enable-sasl --prefix="${HOME}/memcached" + make + make install + popd + + sudo apt-get install sasl2-bin + export SASL_CONF_PATH="${HOME}/sasl2" + + # Create config path + mkdir "${SASL_CONF_PATH}" + + # Create configuration + cat< "${SASL_CONF_PATH}/memcached.conf" +mech_list: PLAIN +plainlog_level: 5 +sasldb_path: ${SASL_CONF_PATH}/sasldb2 +EOF + + # Create password + echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${SASL_CONF_PATH}/sasldb2" + + # Run memcached on port 11212 with SASL support + "${HOME}/memcached/bin/memcached" -S -d -p 11212 +} + +function build_php_memcached() { + pear package + mkdir "$PHP_MEMCACHED_BUILD_DIR" + tar xfz "memcached-${PHP_MEMCACHED_VERSION}.tgz" -C "$PHP_MEMCACHED_BUILD_DIR" + pushd "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}" + phpize + + local protocol_flag="" + if test "x$ENABLE_PROTOCOL" = "xyes"; then + protocol_flag="--enable-memcached-protocol" + fi + + local sasl_flag="--disable-memcached-sasl" + if test "x$ENABLE_SASL" = "xyes"; then + sasl_flag="--enable-memcached-sasl" + fi + + ./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag --enable-memcached-json --enable-memcached-igbinary --enable-memcached-msgpack + make + make install + popd +} + +function create_memcached_test_configuration() { +cat< "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}/tests/config.inc.local" +/dev/null`; do + echo "-- START ${i}"; + cat $i; + echo ""; + echo "-- END"; + done + popd + + return $retval; +} + +# Command line arguments +ACTION=$1 +LIBMEMCACHED_VERSION=$2 + +if test "x$ACTION" = "x"; then + echo "Usage: $0 " + exit 1 +fi + +if test "x$LIBMEMCACHED_VERSION" = "x"; then + echo "Usage: $0 " + exit 1 +fi + +# the extension version +PHP_MEMCACHED_VERSION=$(php -r '$sxe = simplexml_load_file ("package.xml"); echo (string) $sxe->version->release;') + +# Libmemcached install dir +LIBMEMCACHED_PREFIX="${HOME}/libmemcached-${LIBMEMCACHED_VERSION}" + +# Where to do the build +PHP_MEMCACHED_BUILD_DIR="/tmp/php-memcached-build" + +# Check whether to enable building with protoocol and sasl support +check_protocol_support +check_sasl_support + +echo "Enable protocol: $ENABLE_PROTOOCOL" +echo "Enable sasl: $ENABLE_SASL" + +set -e + +case $ACTION in + before_script) + # validate the package.xml + validate_package_xml || exit 1 + + # Install libmemcached version + install_libmemcached + + # Install igbinary extension + install_igbinary + + # install msgpack + install_msgpack + + # install SASL + if test "x$ENABLE_SASL" = "xyes"; then + install_sasl + fi + ;; + + script) + # Build the extension + build_php_memcached + + # Create configuration + if test "x$ENABLE_SASL" = "xyes"; then + create_memcached_test_configuration + fi + + # Run tests + set +e + run_memcached_tests || exit 1 + ;; + + *) + echo "Unknown action. Valid actions are: before_script and script" + exit 1 + ;; +esac + + + + + diff --git a/ChangeLog b/ChangeLog index 2ba3b177..7e43c6b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ Version 2.2.0b1 * Added support for memcached protocol handlers * Added Memcached::setBucket for virtual bucket support * Added support for msgpack serialization + * Memcached::setSaslAuthData returns correct status on success Version 2.1.0 ------------- diff --git a/config.m4 b/config.m4 index 2d7ee2c9..8bdc5749 100644 --- a/config.m4 +++ b/config.m4 @@ -268,13 +268,6 @@ if test "$PHP_MEMCACHED" != "no"; then AC_MSG_RESULT([disabled]) fi - - if test "$PHP_MEMCACHED_SASL" != "no"; then - AC_CHECK_HEADERS([sasl/sasl.h], [memcached_enable_sasl="yes"], [memcached_enable_sasl="no"]) - AC_MSG_CHECKING([whether to enable sasl support]) - AC_MSG_RESULT([$memcached_enable_sasl]) - fi - AC_MSG_CHECKING([for libmemcached location]) export ORIG_PKG_CONFIG_PATH="$PKG_CONFIG_PATH" @@ -362,6 +355,41 @@ if test "$PHP_MEMCACHED" != "no"; then ) ]) + AC_MSG_CHECKING([whether to enable sasl support]) + if test "$PHP_MEMCACHED_SASL" != "no"; then + AC_MSG_RESULT(yes) + + AC_CHECK_HEADERS([sasl/sasl.h], [ac_cv_have_memc_sasl_h="yes"], [ac_cv_have_memc_sasl_h="no"]) + + if test "$ac_cv_have_memc_sasl_h" = "yes"; then + + AC_CACHE_CHECK([whether libmemcached supports sasl], ac_cv_memc_sasl_support, [ + AC_TRY_COMPILE( + [ #include ], + [ + #if LIBMEMCACHED_WITH_SASL_SUPPORT + /* yes */ + #else + # error "no sasl support" + #endif + ], + [ ac_cv_memc_sasl_support="yes" ], + [ ac_cv_memc_sasl_support="no" ] + ) + ]) + + if test "$ac_cv_memc_sasl_support" = "yes"; then + AC_DEFINE(HAVE_MEMCACHED_SASL, 1, [Have SASL support]) + else + AC_MSG_ERROR([no, libmemcached sasl support is not enabled. Run configure with --disable-memcached-sasl to disable this check]) + fi + else + AC_MSG_ERROR([no, sasl.h is not available. Run configure with --disable-memcached-sasl to disable this check]) + fi + else + AC_MSG_RESULT([no]) + fi + CFLAGS="$ORIG_CFLAGS" LIBS="$ORIG_LIBS" diff --git a/package.xml b/package.xml index f3f06d1a..1a5d7e7e 100644 --- a/package.xml +++ b/package.xml @@ -49,6 +49,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Added support for memcached protocol handlers - Added Memcached::setBucket for virtual bucket support - Added support for msgpack serialization +- Memcached::setSaslAuthData returns correct status on success @@ -63,6 +64,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -147,6 +149,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/php_libmemcached_compat.h b/php_libmemcached_compat.h index 19b0ac05..9162a279 100644 --- a/php_libmemcached_compat.h +++ b/php_libmemcached_compat.h @@ -30,4 +30,10 @@ memcached_st *php_memc_create_str (const char *str, size_t str_len); # define MEMCACHED_SERVER_TEMPORARILY_DISABLED (1024 << 2) #endif +#ifdef HAVE_MEMCACHED_INSTANCE_ST +typedef const memcached_instance_st * php_memcached_instance_st; +#else +typedef memcached_server_instance_st php_memcached_instance_st; +#endif + #endif diff --git a/php_memcached.c b/php_memcached.c index 80da7577..da194412 100644 --- a/php_memcached.c +++ b/php_memcached.c @@ -44,53 +44,18 @@ #include #include -#include "php_memcached_server.h" #include "php_memcached.h" +#include "php_memcached_private.h" +#include "php_memcached_server.h" #include "g_fmt.h" #ifdef HAVE_MEMCACHED_SESSION # include "php_memcached_session.h" #endif - - #include "fastlz/fastlz.h" #include -/* Compatibility with older versions */ -#ifdef HAVE_MEMCACHED_INSTANCE_ST -typedef const memcached_instance_st * php_memcached_instance_st; -#else -typedef memcached_server_instance_st php_memcached_instance_st; -#endif - -/* Used to store the size of the block */ -#if defined(HAVE_INTTYPES_H) -#include -#elif defined(HAVE_STDINT_H) -#include -#endif - -#ifdef PHP_WIN32 -# include "win32/php_stdint.h" -#else -# ifndef HAVE_INT32_T -# if SIZEOF_INT == 4 -typedef int int32_t; -# elif SIZEOF_LONG == 4 -typedef long int int32_t; -# endif -# endif - -# ifndef HAVE_UINT32_T -# if SIZEOF_INT == 4 -typedef unsigned int uint32_t; -# elif SIZEOF_LONG == 4 -typedef unsigned long int uint32_t; -# endif -# endif -#endif - #ifdef HAVE_JSON_API # include "ext/json/php_json.h" #endif @@ -2770,6 +2735,7 @@ static PHP_METHOD(Memcached, setOption) static PHP_METHOD(Memcached, setSaslAuthData) { MEMC_METHOD_INIT_VARS; + memcached_return status; char *user, *pass; int user_len, pass_len; @@ -2790,7 +2756,12 @@ static PHP_METHOD(Memcached, setSaslAuthData) RETURN_FALSE; } m_obj->has_sasl_data = 1; - RETURN_BOOL(memcached_set_sasl_auth_data(m_obj->memc, user, pass)); + status = memcached_set_sasl_auth_data(m_obj->memc, user, pass); + + if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { + RETURN_FALSE; + } + RETURN_TRUE; } /* }}} */ #endif /* HAVE_MEMCACHED_SASL */ @@ -3593,19 +3564,19 @@ static void php_memc_destroy_globals(zend_php_memcached_globals *php_memcached_g { } -PHP_MEMCACHED_API +PHPAPI zend_class_entry *php_memc_get_ce(void) { return memcached_ce; } -PHP_MEMCACHED_API +PHPAPI zend_class_entry *php_memc_get_exception(void) { return memcached_exception_ce; } -PHP_MEMCACHED_API +PHPAPI zend_class_entry *php_memc_get_exception_base(int root TSRMLS_DC) { #if HAVE_SPL @@ -4446,8 +4417,8 @@ static void php_memc_register_constants(INIT_FUNC_ARGS) #endif #if HAVE_MEMCACHED_SASL - REGISTER_MEMC_CLASS_CONST_LONG(RES_AUTH_PROBLEM, MEMCACHED_AUTH_PROBLEM); - REGISTER_MEMC_CLASS_CONST_LONG(RES_AUTH_FAILURE, MEMCACHED_AUTH_FAILURE); + REGISTER_MEMC_CLASS_CONST_LONG(RES_AUTH_PROBLEM, MEMCACHED_AUTH_PROBLEM); + REGISTER_MEMC_CLASS_CONST_LONG(RES_AUTH_FAILURE, MEMCACHED_AUTH_FAILURE); REGISTER_MEMC_CLASS_CONST_LONG(RES_AUTH_CONTINUE, MEMCACHED_AUTH_CONTINUE); #endif diff --git a/php_memcached.h b/php_memcached.h index 4a68eb7e..4c3eb4de 100644 --- a/php_memcached.h +++ b/php_memcached.h @@ -19,146 +19,20 @@ #ifndef PHP_MEMCACHED_H #define PHP_MEMCACHED_H -#include "php_libmemcached_compat.h" +#include "php.h" #ifdef HAVE_CONFIG_H # include "config.h" #endif -extern zend_module_entry memcached_module_entry; -#define phpext_memcached_ptr &memcached_module_entry - -#ifdef PHP_WIN32 -#define PHP_MEMCACHED_API __declspec(dllexport) -#else -#define PHP_MEMCACHED_API -#endif - -/**************************************** - Structures and definitions -****************************************/ -enum memcached_serializer { - SERIALIZER_PHP = 1, - SERIALIZER_IGBINARY = 2, - SERIALIZER_JSON = 3, - SERIALIZER_JSON_ARRAY = 4, - SERIALIZER_MSGPACK = 5, -}; -#ifdef HAVE_MEMCACHED_IGBINARY -#define SERIALIZER_DEFAULT SERIALIZER_IGBINARY -#define SERIALIZER_DEFAULT_NAME "igbinary" -#elif HAVE_MEMCACHED_MSGPACK -#define SERIALIZER_DEFAULT SERIALIZER_MSGPACK -#define SERIALIZER_DEFAULT_NAME "msgpack" -#else -#define SERIALIZER_DEFAULT SERIALIZER_PHP -#define SERIALIZER_DEFAULT_NAME "php" -#endif /* HAVE_MEMCACHED_IGBINARY / HAVE_MEMCACHED_MSGPACK */ - -#if LIBMEMCACHED_WITH_SASL_SUPPORT -# if defined(HAVE_SASL_SASL_H) -# include -# define HAVE_MEMCACHED_SASL 1 -# endif -#endif - -#ifdef HAVE_MEMCACHED_PROTOCOL -typedef enum { - MEMC_SERVER_ON_MIN = -1, - MEMC_SERVER_ON_CONNECT = 0, - MEMC_SERVER_ON_ADD = 1, - MEMC_SERVER_ON_APPEND = 2, - MEMC_SERVER_ON_DECREMENT = 3, - MEMC_SERVER_ON_DELETE = 4, - MEMC_SERVER_ON_FLUSH = 5, - MEMC_SERVER_ON_GET = 6, - MEMC_SERVER_ON_INCREMENT = 7, - MEMC_SERVER_ON_NOOP = 8, - MEMC_SERVER_ON_PREPEND = 9, - MEMC_SERVER_ON_QUIT = 10, - MEMC_SERVER_ON_REPLACE = 11, - MEMC_SERVER_ON_SET = 12, - MEMC_SERVER_ON_STAT = 13, - MEMC_SERVER_ON_VERSION = 14, - MEMC_SERVER_ON_MAX -} php_memc_event_t; - - -typedef struct { - zend_fcall_info fci; - zend_fcall_info_cache fci_cache; -} php_memc_server_cb_t; -#endif - -ZEND_BEGIN_MODULE_GLOBALS(php_memcached) -#ifdef HAVE_MEMCACHED_SESSION - zend_bool sess_locking_enabled; - long sess_lock_wait; - long sess_lock_max_wait; - long sess_lock_expire; - char* sess_prefix; - zend_bool sess_locked; - char* sess_lock_key; - int sess_lock_key_len; - - int sess_number_of_replicas; - zend_bool sess_randomize_replica_read; - zend_bool sess_remove_failed_enabled; - long sess_connect_timeout; - zend_bool sess_consistent_hash_enabled; - zend_bool sess_binary_enabled; - - char *sess_sasl_username; - char *sess_sasl_password; -#if HAVE_MEMCACHED_SASL - zend_bool sess_sasl_data; -#endif -#endif - char *serializer_name; - enum memcached_serializer serializer; - - char *compression_type; - int compression_type_real; - int compression_threshold; - - double compression_factor; -#if HAVE_MEMCACHED_SASL - zend_bool use_sasl; -#endif -#ifdef HAVE_MEMCACHED_PROTOCOL - struct { - php_memc_server_cb_t callbacks [14]; - } server; -#endif - long store_retry_count; -ZEND_END_MODULE_GLOBALS(php_memcached) - -PHP_MEMCACHED_API zend_class_entry *php_memc_get_ce(void); -PHP_MEMCACHED_API zend_class_entry *php_memc_get_exception(void); -PHP_MEMCACHED_API zend_class_entry *php_memc_get_exception_base(int root TSRMLS_DC); - -PHP_RINIT_FUNCTION(memcached); -PHP_RSHUTDOWN_FUNCTION(memcached); -PHP_MINIT_FUNCTION(memcached); -PHP_MSHUTDOWN_FUNCTION(memcached); -PHP_MINFO_FUNCTION(memcached); - #define PHP_MEMCACHED_VERSION "2.2.0b1" -#ifdef ZTS -#define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, v) -#else -#define MEMC_G(v) (php_memcached_globals.v) -#endif - -typedef struct { - memcached_st *memc_sess; - zend_bool is_persistent; -} memcached_sess; +PHPAPI zend_class_entry *php_memc_get_ce(void); +PHPAPI zend_class_entry *php_memc_get_exception(void); +PHPAPI zend_class_entry *php_memc_get_exception_base(int root TSRMLS_DC); -int php_memc_sess_list_entry(void); - -char *php_memc_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC); +extern zend_module_entry memcached_module_entry; +#define phpext_memcached_ptr &memcached_module_entry #endif /* PHP_MEMCACHED_H */ diff --git a/php_memcached_private.h b/php_memcached_private.h new file mode 100644 index 00000000..0fabc1f5 --- /dev/null +++ b/php_memcached_private.h @@ -0,0 +1,184 @@ +/* + +----------------------------------------------------------------------+ + | 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 | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Andrei Zmievski | + +----------------------------------------------------------------------+ +*/ + +/* $ Id: $ */ + +#ifndef PHP_MEMCACHED_PRIVATE_H +#define PHP_MEMCACHED_PRIVATE_H + +#include "php_libmemcached_compat.h" + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef PHP_WIN32 +# include "win32/php_stdint.h" +#else +/* Used to store the size of the block */ +# if defined(HAVE_INTTYPES_H) +# include +# elif defined(HAVE_STDINT_H) +# include +# endif +#endif + +#ifndef HAVE_INT32_T +# if SIZEOF_INT == 4 +typedef int int32_t; +# elif SIZEOF_LONG == 4 +typedef long int int32_t; +# endif +#endif + +#ifndef HAVE_UINT32_T +# if SIZEOF_INT == 4 +typedef unsigned int uint32_t; +# elif SIZEOF_LONG == 4 +typedef unsigned long int uint32_t; +# endif +#endif + +/**************************************** + Structures and definitions +****************************************/ +enum memcached_serializer { + SERIALIZER_PHP = 1, + SERIALIZER_IGBINARY = 2, + SERIALIZER_JSON = 3, + SERIALIZER_JSON_ARRAY = 4, + SERIALIZER_MSGPACK = 5, +}; +#ifdef HAVE_MEMCACHED_IGBINARY +#define SERIALIZER_DEFAULT SERIALIZER_IGBINARY +#define SERIALIZER_DEFAULT_NAME "igbinary" +#elif HAVE_MEMCACHED_MSGPACK +#define SERIALIZER_DEFAULT SERIALIZER_MSGPACK +#define SERIALIZER_DEFAULT_NAME "msgpack" +#else +#define SERIALIZER_DEFAULT SERIALIZER_PHP +#define SERIALIZER_DEFAULT_NAME "php" +#endif /* HAVE_MEMCACHED_IGBINARY / HAVE_MEMCACHED_MSGPACK */ + +#if LIBMEMCACHED_WITH_SASL_SUPPORT +# if defined(HAVE_SASL_SASL_H) +# include +# define HAVE_MEMCACHED_SASL 1 +# endif +#endif + +#ifdef HAVE_MEMCACHED_PROTOCOL +typedef enum { + MEMC_SERVER_ON_MIN = -1, + MEMC_SERVER_ON_CONNECT = 0, + MEMC_SERVER_ON_ADD = 1, + MEMC_SERVER_ON_APPEND = 2, + MEMC_SERVER_ON_DECREMENT = 3, + MEMC_SERVER_ON_DELETE = 4, + MEMC_SERVER_ON_FLUSH = 5, + MEMC_SERVER_ON_GET = 6, + MEMC_SERVER_ON_INCREMENT = 7, + MEMC_SERVER_ON_NOOP = 8, + MEMC_SERVER_ON_PREPEND = 9, + MEMC_SERVER_ON_QUIT = 10, + MEMC_SERVER_ON_REPLACE = 11, + MEMC_SERVER_ON_SET = 12, + MEMC_SERVER_ON_STAT = 13, + MEMC_SERVER_ON_VERSION = 14, + MEMC_SERVER_ON_MAX +} php_memc_event_t; + + +typedef struct { + zend_fcall_info fci; + zend_fcall_info_cache fci_cache; +} php_memc_server_cb_t; +#endif + +ZEND_BEGIN_MODULE_GLOBALS(php_memcached) +#ifdef HAVE_MEMCACHED_SESSION + zend_bool sess_locking_enabled; + long sess_lock_wait; + long sess_lock_max_wait; + long sess_lock_expire; + char* sess_prefix; + zend_bool sess_locked; + char* sess_lock_key; + int sess_lock_key_len; + + int sess_number_of_replicas; + zend_bool sess_randomize_replica_read; + zend_bool sess_remove_failed_enabled; + long sess_connect_timeout; + zend_bool sess_consistent_hash_enabled; + zend_bool sess_binary_enabled; + + char *sess_sasl_username; + char *sess_sasl_password; +#if HAVE_MEMCACHED_SASL + zend_bool sess_sasl_data; +#endif +#endif + char *serializer_name; + enum memcached_serializer serializer; + + char *compression_type; + int compression_type_real; + int compression_threshold; + + double compression_factor; +#if HAVE_MEMCACHED_SASL + zend_bool use_sasl; +#endif +#ifdef HAVE_MEMCACHED_PROTOCOL + struct { + php_memc_server_cb_t callbacks [14]; + } server; +#endif + long store_retry_count; +ZEND_END_MODULE_GLOBALS(php_memcached) + +PHP_RINIT_FUNCTION(memcached); +PHP_RSHUTDOWN_FUNCTION(memcached); +PHP_MINIT_FUNCTION(memcached); +PHP_MSHUTDOWN_FUNCTION(memcached); +PHP_MINFO_FUNCTION(memcached); + +#ifdef ZTS +#define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, v) +#else +#define MEMC_G(v) (php_memcached_globals.v) +#endif + +typedef struct { + memcached_st *memc_sess; + zend_bool is_persistent; +} memcached_sess; + +int php_memc_sess_list_entry(void); + +char *php_memc_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC); + +#endif /* PHP_MEMCACHED_PRIVATE_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/php_memcached_server.c b/php_memcached_server.c index 8c5db704..5cead492 100644 --- a/php_memcached_server.c +++ b/php_memcached_server.c @@ -20,6 +20,7 @@ #include #include "php_memcached.h" +#include "php_memcached_private.h" #include "php_memcached_server.h" #include "php_libmemcached_compat.h" diff --git a/php_memcached_session.c b/php_memcached_session.c index 9d538cfa..8b4b95f7 100644 --- a/php_memcached_session.c +++ b/php_memcached_session.c @@ -32,6 +32,7 @@ #include #include "php_memcached.h" +#include "php_memcached_private.h" #include "php_memcached_session.h" extern ZEND_DECLARE_MODULE_GLOBALS(php_memcached) diff --git a/tests/config.inc b/tests/config.inc index 5edfa2cc..6d298487 100644 --- a/tests/config.inc +++ b/tests/config.inc @@ -1,19 +1,40 @@ setOptions ($opts) == false) echo "Failed to set options" . PHP_EOL; - $memcached->addServer(MEMC_SERVER_HOST, MEMC_SERVER_PORT); + $memcached->addServer($host, $port); $memcached->flush (); return $memcached; } +function memc_get_instance (array $opts = array (), $persistent_id = null) +{ + return memc_create_instance(MEMC_SERVER_HOST, MEMC_SERVER_PORT, $opts, $persistent_id); +} + +function memc_get_sasl_instance (array $opts = array (), $persistent_id = null) +{ + return memc_create_instance(MEMC_SASL_SERVER_HOST, MEMC_SASL_SERVER_PORT, $opts, $persistent_id); +} + function memc_run_test ($test_function, $options = array ()) { foreach ($options as $option_set) { @@ -43,21 +64,3 @@ function memc_create_combinations ($name, $serializer, $ignore_object_type = fal ), ); } - -function memc_get_serializer_options ($skipmsgpack=false) -{ - $options = memc_create_combinations ('PHP', Memcached::SERIALIZER_PHP); - - if (Memcached::HAVE_IGBINARY) { - $options = array_merge ($options, memc_create_combinations ('igbinary', Memcached::SERIALIZER_IGBINARY)); - } - - if (Memcached::HAVE_JSON) { - $options = array_merge ($options, memc_create_combinations ('JSON', Memcached::SERIALIZER_JSON, true)); - } - - if (Memcached::HAVE_MSGPACK && !$skipmsgpack) { - $options = array_merge ($options, memc_create_combinations ('msgpack', Memcached::SERIALIZER_MSGPACK)); - } - return $options; -} diff --git a/tests/sasl_basic.phpt b/tests/sasl_basic.phpt new file mode 100644 index 00000000..03fcb98b --- /dev/null +++ b/tests/sasl_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test SASL authentication +--SKIPIF-- + +--INI-- +memcached.use_sasl = on +--FILE-- + true + )); + +var_dump ($m->setSaslAuthData (MEMC_SASL_USER, MEMC_SASL_PASS)); + +$key = uniqid ('sasl_test_'); +var_dump ($m->set ($key, 'set using sasl')); +var_dump ($m->get ($key)); + + +echo "OK" . PHP_EOL; +?> +--EXPECT-- +bool(true) +bool(true) +string(14) "set using sasl" +OK diff --git a/travis.sh b/travis.sh deleted file mode 100755 index 51afd8df..00000000 --- a/travis.sh +++ /dev/null @@ -1,178 +0,0 @@ -#!/bin/bash - -function validate_package_xml() { - retval=0 - for file in tests/*.phpt; do - grep $(basename $file) package.xml >/dev/null - if [ $? != 0 ]; then - echo "Missing $file from package.xml" - retval=1; - fi - done - return $retval; -} - -function install_libmemcached() { - local libmemcached_version=$1 - local libmemcached_prefix=$2 - local enable_protocol=$3 - - wget "https://launchpad.net/libmemcached/1.0/${libmemcached_version}/+download/libmemcached-${libmemcached_version}.tar.gz" -O libmemcached-${libmemcached_version}.tar.gz - - tar xvfz libmemcached-${libmemcached_version}.tar.gz - pushd "libmemcached-${libmemcached_version}" - - if test "x$enable_protocol" = "xyes"; then - protocol_flag="--enable-libmemcachedprotocol" - fi - - ./configure --prefix="$PHP_LIBMEMCACHED_PREFIX" $protocol_flag LDFLAGS="-lpthread" - make - make install - popd -} - -function install_igbinary() { - git clone https://github.com/igbinary/igbinary.git - pushd igbinary - phpize - ./configure - make - make install - popd -} - -function install_msgpack() { - git clone https://github.com/msgpack/msgpack-php.git - pushd msgpack-php - phpize - ./configure - make - make install - popd -} - -function build_php_memcached() { - local libmemcached_prefix=$1 - local php_memcached_version=$2 - local enable_protocol=$3 - - pear package - mkdir /tmp/php-memcached-build - tar xfz "memcached-${php_memcached_version}.tgz" -C /tmp/php-memcached-build - pushd "/tmp/php-memcached-build/memcached-${php_memcached_version}" - phpize - - if test "x$enable_protocol" = "xyes"; then - protocol_flag="--enable-memcached-protocol" - fi - - ./configure --with-libmemcached-dir="$libmemcached_prefix" $protocol_flag --enable-memcached-json --enable-memcached-igbinary --enable-memcached-msgpack - make - make install - popd -} - -function run_memcached_tests() { - local php_memcached_version=$1 - - export NO_INTERACTION=1 - export REPORT_EXIT_STATUS=1 - export TEST_PHP_EXECUTABLE=`which php` - - pushd "/tmp/php-memcached-build/memcached-${php_memcached_version}" - # We have one xfail test, we run it separately - php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/expire.phpt - rm ./tests/expire.phpt - - php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/*.phpt - retval=$? - for i in `ls tests/*.out 2>/dev/null`; do - echo "-- START ${i}"; - cat $i; - echo ""; - echo "-- END"; - done - popd - - return $retval; -} - -# Command line arguments -ACTION=$1 -PHP_LIBMEMCACHED_VERSION=$2 - -if test "x$ACTION" = "x"; then - echo "Usage: $0 " - exit 1 -fi - -if test "x$PHP_LIBMEMCACHED_VERSION" = "x"; then - echo "Usage: $0 " - exit 1 -fi - -# the extension version -PHP_MEMCACHED_VERSION=$(php -r '$sxe = simplexml_load_file ("package.xml"); echo (string) $sxe->version->release;') - -# Libmemcached install dir -PHP_LIBMEMCACHED_PREFIX="${HOME}/libmemcached-${PHP_LIBMEMCACHED_VERSION}" - -# Check whether to enable building with protoocol support -DPKG=`which dpkg` - -if [ "x$DPKG" = "x" ]; then - echo "dpkg not found, enabling protocol support" - ENABLE_PROTOOCOL=yes -else - dpkg --compare-versions "$PHP_LIBMEMCACHED_VERSION" gt 1.0.15 - if [ $? = 0 ]; then - ENABLE_PROTOOCOL=yes - else - ENABLE_PROTOOCOL=no - fi -fi - -echo "Enable protocol: $ENABLE_PROTOOCOL" - -set -e - -case $ACTION in - before_script) - # validate the package.xml - validate_package_xml || exit 1 - - # Install libmemcached version - install_libmemcached $PHP_LIBMEMCACHED_VERSION $PHP_LIBMEMCACHED_PREFIX $ENABLE_PROTOOCOL - - # Install igbinary extension - install_igbinary - - # install msgpack - install_msgpack - ;; - - script) - # Build the extension - build_php_memcached $PHP_LIBMEMCACHED_PREFIX $PHP_MEMCACHED_VERSION $ENABLE_PROTOOCOL - - # Make sure that memcached is running - sudo service memcached restart - netstat -an | grep LISTEN - nc -vv -z 127.0.0.1 11211 - - # Run tests - set +e - run_memcached_tests $PHP_MEMCACHED_VERSION || exit 1 - ;; - - *) - echo "Unknown action. Valid actions are: before_script and script" - exit 1 - ;; -esac - - - - -