diff --git a/.travis.yml b/.travis.yml index d529cf50..311821ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,27 +1,31 @@ +sudo: required +dist: trusty + language: php php: - 5.5 - #- 5.4 - #- 5.3 + - 5.6 + env: - - LIBMEMCACHED_VERSION=1.0.17 - - LIBMEMCACHED_VERSION=1.0.16 - - LIBMEMCACHED_VERSION=1.0.15 - - 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.49 - - LIBMEMCACHED_VERSION=0.44 + - 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 + - LIBMEMCACHED_VERSION=0.53 # Ancient -services: - - memcached # will start memcached +addons: + apt: + packages: + - sasl2-bin + - libsasl2-dev + - libevent-dev before_script: - ./.travis/travis.sh before_script $LIBMEMCACHED_VERSION script: - ./.travis/travis.sh script $LIBMEMCACHED_VERSION + +cache: + directories: + - $HOME/cache diff --git a/.travis/travis.sh b/.travis/travis.sh index 05f3da95..ef665f02 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -44,6 +44,12 @@ function validate_package_xml() { function install_libmemcached() { + if test -d "${LIBMEMCACHED_PREFIX}" + then + echo "Using cached libmemcached: ${LIBMEMCACHED_PREFIX}" + return + fi + 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 @@ -81,35 +87,52 @@ function install_msgpack() { popd } -function install_sasl() { +function install_memcached() { + local prefix="${HOME}/cache/memcached-sasl-${MEMCACHED_VERSION}" + + if test -d "$prefix" + then + echo "Using cached memcached: ${prefix}" + return + fi - 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 + wget http://www.memcached.org/files/memcached-${MEMCACHED_VERSION}.tar.gz -O memcached-${MEMCACHED_VERSION}.tar.gz + tar xfz memcached-${MEMCACHED_VERSION}.tar.gz - pushd memcached-1.4.15 - ./configure --enable-sasl --prefix="${HOME}/memcached" + pushd memcached-${MEMCACHED_VERSION} + ./configure --enable-sasl --enable-sasl-pwdb --prefix="${prefix}" make make install popd +} + +function run_memcached() { + local prefix="${HOME}/cache/memcached-sasl-${MEMCACHED_VERSION}" - sudo apt-get install sasl2-bin - export SASL_CONF_PATH="${HOME}/sasl2" + export SASL_CONF_PATH="/tmp/sasl2" + + if test -d "${SASL_CONF_PATH}" + then + rm -rf "${SASL_CONF_PATH}" + fi - # Create config path mkdir "${SASL_CONF_PATH}" + export MEMCACHED_SASL_PWDB="${SASL_CONF_PATH}/sasldb2" # Create configuration cat< "${SASL_CONF_PATH}/memcached.conf" mech_list: PLAIN plainlog_level: 5 -sasldb_path: ${SASL_CONF_PATH}/sasldb2 +sasldb_path: ${MEMCACHED_SASL_PWDB} EOF - # Create password - echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${SASL_CONF_PATH}/sasldb2" + echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${MEMCACHED_SASL_PWDB}" + + # Run normal memcached + "${prefix}/bin/memcached" -d -p 11211 # Run memcached on port 11212 with SASL support - "${HOME}/memcached/bin/memcached" -S -d -p 11212 + "${prefix}/bin/memcached" -S -d -p 11212 } function build_php_memcached() { @@ -129,7 +152,8 @@ function build_php_memcached() { 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 + # ./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag + ./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag --enable-memcached-json --enable-memcached-msgpack --enable-memcached-igbinary make make install popd @@ -152,30 +176,24 @@ EOF function run_memcached_tests() { export NO_INTERACTION=1 export REPORT_EXIT_STATUS=1 - export TEST_PHP_EXECUTABLE=`which php` + export TEST_PHP_EXECUTABLE=$(which php) pushd "${PHP_MEMCACHED_BUILD_DIR}/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 + php run-tests.php -d extension=memcached.so -n ./tests/expire.phpt rm ./tests/expire.phpt # Run normal tests - php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/*.phpt + php run-tests.php --show-diff -d extension=modules/memcached.so -d extension=msgpack.so -d extension=igbinary.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 LIBMEMCACHED_VERSION=$2 +MEMCACHED_VERSION="1.4.25" if test "x$ACTION" = "x"; then echo "Usage: $0 " @@ -187,11 +205,15 @@ if test "x$LIBMEMCACHED_VERSION" = "x"; then exit 1 fi +if test "x$3" != "x"; then + MEMCACHED_VERSION=$3 +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}" +LIBMEMCACHED_PREFIX="${HOME}/cache/libmemcached-${LIBMEMCACHED_VERSION}" # Where to do the build PHP_MEMCACHED_BUILD_DIR="/tmp/php-memcached-build" @@ -216,13 +238,11 @@ case $ACTION in # Install igbinary extension install_igbinary - # install msgpack + # Install msgpack extension install_msgpack - - # install SASL - if test "x$ENABLE_SASL" = "xyes"; then - install_sasl - fi + + install_memcached + run_memcached ;; script) diff --git a/php_memcached_session.c b/php_memcached_session.c index a4e89aed..66a25f55 100644 --- a/php_memcached_session.c +++ b/php_memcached_session.c @@ -154,16 +154,6 @@ PS_OPEN_FUNC(memcached) status = memcached_server_push(memc_sess->memc_sess, servers); memcached_server_list_free(servers); - if (MEMC_G(sess_prefix) && MEMC_G(sess_prefix)[0] != 0 && memcached_callback_set(memc_sess->memc_sess, MEMCACHED_CALLBACK_PREFIX_KEY, MEMC_G(sess_prefix)) != MEMCACHED_SUCCESS) { - PS_SET_MOD_DATA(NULL); - if (plist_key) { - efree(plist_key); - } - memcached_free(memc_sess->memc_sess); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "bad memcached key prefix in memcached.sess_prefix"); - return FAILURE; - } - if (status == MEMCACHED_SUCCESS) { goto success; } @@ -211,6 +201,13 @@ PS_OPEN_FUNC(memcached) return FAILURE; } } + + if (MEMC_G(sess_prefix) && MEMC_G(sess_prefix)[0] != 0 ) { + if (memcached_callback_set(memc_sess->memc_sess, MEMCACHED_CALLBACK_PREFIX_KEY, MEMC_G(sess_prefix)) != MEMCACHED_SUCCESS) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "bad memcached key prefix in memcached.sess_prefix"); + return FAILURE; + } + } #ifdef HAVE_MEMCACHED_SASL if (MEMC_G(use_sasl)) { /* @@ -331,7 +328,11 @@ PS_READ_FUNC(memcached) *vallen = payload_len; free(payload); return SUCCESS; + } else if (status == MEMCACHED_NOTFOUND) { + /* this is okey, session may not be in memcached yet */ + return FAILURE; } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "error getting session from memcached: %s", memcached_last_error_message(memc_sess->memc_sess)); return FAILURE; } } @@ -371,6 +372,7 @@ PS_WRITE_FUNC(memcached) if (status == MEMCACHED_SUCCESS) { return SUCCESS; } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "error saving session to memcached: %s", memcached_last_error_message(memc_sess->memc_sess)); write_try_attempts--; } } while (write_try_attempts > 0); diff --git a/tests/config.inc b/tests/config.inc index 6d298487..657d41e5 100644 --- a/tests/config.inc +++ b/tests/config.inc @@ -64,3 +64,8 @@ function memc_create_combinations ($name, $serializer, $ignore_object_type = fal ), ); } + +function memc_get_version($memc, $host = '') { + $version = $memc->getVersion(); + return array_pop($version); +} diff --git a/tests/expire.phpt b/tests/expire.phpt index 0c8587ff..eac02408 100644 --- a/tests/expire.phpt +++ b/tests/expire.phpt @@ -3,7 +3,9 @@ Memcached store, fetch & touch expired key --XFAIL-- https://code.google.com/p/memcached/issues/detail?id=275 --SKIPIF-- - --FILE-- diff --git a/tests/gh_155.phpt b/tests/gh_155.phpt index c1f02bc6..42427669 100644 --- a/tests/gh_155.phpt +++ b/tests/gh_155.phpt @@ -1,7 +1,11 @@ --TEST-- Test for bug 155 --SKIPIF-- - + --FILE-- --FILE-- --FILE--