├── .github ├── dependabot.yml └── workflows │ └── build-and-test.yml ├── .gitignore ├── CREDITS ├── ChangeLog ├── INSTALL ├── LICENSE ├── NOTICE ├── README.markdown ├── README.win32.txt ├── config.m4 ├── config.w32 ├── fastlz ├── LICENSE ├── fastlz.c └── fastlz.h ├── g_fmt.c ├── g_fmt.h ├── memcached-api.php ├── memcached.ini ├── package.xml ├── php_libmemcached_compat.c ├── php_libmemcached_compat.h ├── php_memcached.c ├── php_memcached.h ├── php_memcached.stub.php ├── php_memcached_arginfo.h ├── php_memcached_legacy_arginfo.h ├── php_memcached_private.h ├── php_memcached_server.c ├── php_memcached_server.h ├── php_memcached_session.c ├── php_memcached_session.h ├── server-example ├── run-server.php ├── set-get-server.php ├── set-get.php └── test-server.php ├── tests ├── 001.phpt ├── add.phpt ├── append.phpt ├── bad_construct.phpt ├── bad_construct_8.phpt ├── bug_16084.phpt ├── bug_16959.phpt ├── bug_17137.phpt ├── bug_18639.phpt ├── cachecallback.phpt ├── callback_exception.phpt ├── callback_exception_2.phpt ├── cas.phpt ├── cas_multi.phpt ├── check_if_persistent.phpt ├── check_if_pristine.phpt ├── check_key.phpt ├── clone.phpt ├── compression_conditions.phpt ├── compression_types.phpt ├── conf_persist.phpt ├── config.inc ├── construct.phpt ├── construct_persistent.phpt ├── default_behavior.phpt ├── deleted.phpt ├── deletemulti.phpt ├── deletemultitypes.phpt ├── experimental │ ├── add_bykey.phpt │ ├── addserver_unixdomain.phpt │ ├── append_bykey.phpt │ ├── cas_bykey.phpt │ ├── cas_invalid_key.phpt │ ├── delete_bykey.phpt │ ├── deletemulti_nonstringkeys.phpt │ ├── extreme_floats.phpt │ ├── fetch.phpt │ ├── fetch_badunserialize.phpt │ ├── fetchall_badunserialize.phpt │ ├── get.phpt │ ├── get_bykey.phpt │ ├── get_bykey_cas.phpt │ ├── get_udp.phpt │ ├── getdelayed_badserver.phpt │ ├── getdelayed_badunserialize.phpt │ ├── getdelayed_bykey.phpt │ ├── getdelayed_bykey_cas.phpt │ ├── getdelayed_cbthrows.phpt │ ├── getdelayed_nonstring_keys.phpt │ ├── getmulti_badserver.phpt │ ├── getmulti_badunserialize.phpt │ ├── getmulti_bykey.phpt │ ├── getmulti_empty.phpt │ ├── getmulti_partial_error.phpt │ ├── getversion.phpt │ ├── locale_float.phpt │ ├── moduleinfo.phpt │ ├── prepend_bykey.phpt │ ├── replace_bykey.phpt │ ├── serializer │ │ ├── serializer_php.phpt │ │ ├── serializer_php_bad_serialize.phpt │ │ └── serializer_php_bad_unserialize.phpt │ ├── serializer_igbinary.phpt │ ├── serializer_json.phpt │ ├── session_gc.phpt │ ├── set_bykey.phpt │ ├── set_comp_below_factor.phpt │ ├── set_default_serializer.phpt │ ├── set_invalid_serializer.phpt │ ├── setget_zero_factor.phpt │ ├── setmulti_badserialize.phpt │ ├── setmulti_bykey.phpt │ ├── stats.phpt │ └── stats_badserver.phpt ├── expire.phpt ├── flush_buffers.phpt ├── get_flags.phpt ├── getdelayed.phpt ├── getmulti.phpt ├── getserverbykey.phpt ├── getserverlist.phpt ├── gh_155.phpt ├── gh_21.phpt ├── gh_500.phpt ├── gh_77.phpt ├── gh_90.phpt ├── gh_93.phpt ├── incrdecr.phpt ├── incrdecr_64.phpt ├── incrdecr_bykey.phpt ├── incrdecr_initial.phpt ├── incrdecr_invalid_key.phpt ├── invalid_options.phpt ├── invoke_callback.phpt ├── invoke_callback_2.phpt ├── invoke_callback_twice.phpt ├── keys_ascii.phpt ├── keys_binary.phpt ├── localserver.phpt ├── memcachedserver.phpt ├── memcachedserver6.phpt ├── multi_order.phpt ├── no-not-found.phpt ├── options.phpt ├── pr_75.phpt ├── prepend.phpt ├── replace.phpt ├── rescode.phpt ├── reset_keyprefix.phpt ├── sasl_basic.phpt ├── server.inc ├── server.php ├── session_badconf_emptyprefix.phpt ├── session_badconf_locktime.phpt ├── session_badconf_persistent.phpt ├── session_badconf_prefix.phpt ├── session_badconf_servers-php72.phpt ├── session_badconf_servers.phpt ├── session_basic.phpt ├── session_basic2.phpt ├── session_basic3.phpt ├── session_lazy_warning.phpt ├── session_lock-php71.phpt ├── session_lock.phpt ├── session_persistent.phpt ├── session_regenerate.phpt ├── session_tls.phpt ├── set_encoding_key.phpt ├── set_encoding_key2.phpt ├── set_large.phpt ├── setmulti.phpt ├── setoptions.phpt ├── skipif.inc ├── stats.phpt ├── stats_hang.phpt ├── testdata.res ├── tls_basic.phpt ├── touch_binary.phpt ├── types.inc ├── types_igbinary.phpt ├── types_igbinary_multi.phpt ├── types_json.phpt ├── types_json_multi.phpt ├── types_msgpack.phpt ├── types_msgpack_multi.phpt ├── types_php.phpt ├── types_php_multi.phpt ├── undefined_set.phpt ├── user-flags.phpt ├── vbucket.phpt ├── vbucket_error_7.phpt ├── vbucket_error_8.phpt └── version.phpt └── tls-examples ├── memcached-tls-client.php └── memcached-tls-session.php /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "monthly" 7 | -------------------------------------------------------------------------------- /.github/workflows/build-and-test.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | continue-on-error: ${{ matrix.experimental }} 7 | strategy: 8 | fail-fast: false 9 | matrix: 10 | php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] 11 | experimental: [false] 12 | include: 13 | - php: '8.2' 14 | experimental: true 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v3 18 | with: 19 | submodules: true 20 | - name: Install PHP ${{ matrix.php }} 21 | uses: shivammathur/setup-php@v2 22 | with: 23 | php-version: ${{ matrix.php }} 24 | extensions: none, json, igbinary, msgpack 25 | - name: Install dependencies 26 | run: | 27 | sudo apt-get update 28 | sudo apt --fix-broken install 29 | sudo apt-get install memcached libsasl2-dev sasl2-bin zlib1g-dev git libevent-dev gcc g++ make autoconf 30 | - name: Build and install libmemcached 31 | run: | 32 | LIBMEMCACHED_PATH=/home/runner/libmemcached 33 | mkdir $LIBMEMCACHED_PATH 34 | git clone https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached.git 35 | cd aws-elasticache-cluster-client-libmemcached 36 | touch configure.ac aclocal.m4 configure Makefile.am Makefile.in 37 | CFLAGS=-Wno-error CPPFLAGS=-Wno-error ./configure --prefix=${LIBMEMCACHED_PATH} --with-pic 38 | sed -e s/-Werror//g -i ./Makefile 39 | make 40 | sudo make install 41 | - name: Start memcached daemons 42 | run: | 43 | export SASL_CONF_PATH="/tmp/sasl2" 44 | mkdir "${SASL_CONF_PATH}" 45 | export MEMCACHED_SASL_PWDB="${SASL_CONF_PATH}/sasldb2" 46 | 47 | # Create configuration 48 | cat< "${SASL_CONF_PATH}/memcached.conf" 49 | mech_list: PLAIN 50 | plainlog_level: 5 51 | sasldb_path: ${MEMCACHED_SASL_PWDB} 52 | EOF 53 | 54 | echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${MEMCACHED_SASL_PWDB}" 55 | 56 | # Run normal memcached 57 | memcached -d -p 11211 58 | 59 | # Run memcached on port 11212 with SASL support 60 | memcached -S -d -p 11212 61 | - name: Build extension 62 | run: | 63 | phpize 64 | ./configure \ 65 | --with-libmemcached-dir=/home/runner/libmemcached \ 66 | --enable-memcached-protocol=no \ 67 | --enable-memcached-sasl \ 68 | --enable-memcached-json \ 69 | --enable-memcached-msgpack \ 70 | --enable-memcached-igbinary 71 | make 72 | sudo make install 73 | - name: Create test configuration 74 | run: | 75 | cat< tests/config.inc.local 76 | phpize 8 | 9 | > ./configure --with-libmemcached-dir= --disable-memcached-sasl 10 | 11 | > make 12 | 13 | > make install 14 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | aws-elasticache-cluster-client-memcached-for-php 2 | Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | -------------------------------------------------------------------------------- /README.win32.txt: -------------------------------------------------------------------------------- 1 | Build Steps for Windows 2 | ------------------------- 3 | 4 | Follow https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2#building_pecl_extensions 5 | 6 | - Add igbinary module to pecl directory if support desired 7 | - Download/Compile libmemcached & add to deps folders (includes & lib). Lib should be named memcache.lib 8 | - Important for 32bit: libmemcached must be built with _USE_32BIT_TIME_T defined (confirmed on PHP 7.2, VC15) 9 | - https://github.com/yshurik/libmemcached-win/tree/1.0.18 is confirmed working 10 | - To use the dll on the releases page you'd likely need to change the header files to use __time64_t instead of time_t 11 | - Enable all options desired: --enable-memcached=shared --enable-memcached-session --enable-memcached-json 12 | - for igbinary, add --enable-memcached-igbinary --enable-igbinary=shared 13 | - Run nmake -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // vim:ft=javascript 2 | 3 | ARG_ENABLE('memcached', 'libmemcached extension', 'no'); 4 | 5 | ARG_ENABLE('memcached-session', 'whether to enable memcached session handler support', 'no'); 6 | ARG_ENABLE('memcached-igbinary', 'whether to enable memcached igbinary serializer support', 'no'); 7 | ARG_ENABLE('memcached-json', 'whether to enable memcached json serializer support', 'no'); 8 | 9 | if (PHP_MEMCACHED == "yes") { 10 | 11 | if (!CHECK_LIB("memcached.lib;libmemcached.lib", "memcached", PHP_MEMCACHED)) { 12 | ERROR("memcached: library 'memcached' not found"); 13 | } 14 | 15 | if (!CHECK_HEADER_ADD_INCLUDE("libmemcached/memcached.h", "CFLAGS_MEMCACHED")) { 16 | ERROR("memcached: header 'libmemcached/memcached.h' not found"); 17 | } 18 | 19 | if (PHP_MEMCACHED_JSON != "no"){ 20 | AC_DEFINE("HAVE_JSON_API",1); 21 | } 22 | 23 | var memcached_extra_src = ""; 24 | 25 | if (PHP_MEMCACHED_SESSION != "no"){ 26 | AC_DEFINE("HAVE_MEMCACHED_SESSION",1); 27 | ADD_EXTENSION_DEP("memcached", "session", true) 28 | memcached_extra_src += " php_memcached_session.c"; 29 | } 30 | 31 | if (PHP_MEMCACHED_IGBINARY != "no"){ 32 | AC_DEFINE("HAVE_MEMCACHED_IGBINARY",1); 33 | ADD_EXTENSION_DEP("memcached", "igbinary", true); 34 | if (!CHECK_HEADER_ADD_INCLUDE("igbinary.h", "CFLAGS_MEMCACHED")) { 35 | ERROR("memcached: header 'igbinary.h' not found"); 36 | } 37 | } 38 | 39 | EXTENSION("memcached", "php_memcached.c php_libmemcached_compat.c g_fmt.c"+memcached_extra_src, null, " /DHAVE_SSIZE_T"); 40 | ADD_SOURCES(configure_module_dirname+"\\fastlz", "fastlz.c", "memcached"); 41 | AC_DEFINE("HAVE_MEMCACHED", 1, "memcached support"); 42 | AC_DEFINE("MEMCACHED_EXPORTS", 1) 43 | } 44 | -------------------------------------------------------------------------------- /fastlz/LICENSE: -------------------------------------------------------------------------------- 1 | FastLZ - lightning-fast lossless compression library 2 | 3 | Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) 4 | Copyright (C) 2006 Ariya Hidayat (ariya@kde.org) 5 | Copyright (C) 2005 Ariya Hidayat (ariya@kde.org) 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | -------------------------------------------------------------------------------- /fastlz/fastlz.h: -------------------------------------------------------------------------------- 1 | /* 2 | FastLZ - lightning-fast lossless compression library 3 | 4 | Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) 5 | Copyright (C) 2006 Ariya Hidayat (ariya@kde.org) 6 | Copyright (C) 2005 Ariya Hidayat (ariya@kde.org) 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #ifndef FASTLZ_H 28 | #define FASTLZ_H 29 | 30 | #define FASTLZ_VERSION 0x000100 31 | 32 | #define FASTLZ_VERSION_MAJOR 0 33 | #define FASTLZ_VERSION_MINOR 0 34 | #define FASTLZ_VERSION_REVISION 0 35 | 36 | #define FASTLZ_VERSION_STRING "0.1.0" 37 | 38 | #if defined (__cplusplus) 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | Compress a block of data in the input buffer and returns the size of 44 | compressed block. The size of input buffer is specified by length. The 45 | minimum input buffer size is 16. 46 | 47 | The output buffer must be at least 5% larger than the input buffer 48 | and can not be smaller than 66 bytes. 49 | 50 | If the input is not compressible, the return value might be larger than 51 | length (input buffer size). 52 | 53 | The input buffer and the output buffer can not overlap. 54 | */ 55 | 56 | int fastlz_compress(const void* input, int length, void* output); 57 | 58 | /** 59 | Decompress a block of compressed data and returns the size of the 60 | decompressed block. If error occurs, e.g. the compressed data is 61 | corrupted or the output buffer is not large enough, then 0 (zero) 62 | will be returned instead. 63 | 64 | The input buffer and the output buffer can not overlap. 65 | 66 | Decompression is memory safe and guaranteed not to write the output buffer 67 | more than what is specified in maxout. 68 | */ 69 | 70 | int fastlz_decompress(const void* input, int length, void* output, int maxout); 71 | 72 | /** 73 | Compress a block of data in the input buffer and returns the size of 74 | compressed block. The size of input buffer is specified by length. The 75 | minimum input buffer size is 16. 76 | 77 | The output buffer must be at least 5% larger than the input buffer 78 | and can not be smaller than 66 bytes. 79 | 80 | If the input is not compressible, the return value might be larger than 81 | length (input buffer size). 82 | 83 | The input buffer and the output buffer can not overlap. 84 | 85 | Compression level can be specified in parameter level. At the moment, 86 | only level 1 and level 2 are supported. 87 | Level 1 is the fastest compression and generally useful for short data. 88 | Level 2 is slightly slower but it gives better compression ratio. 89 | 90 | Note that the compressed data, regardless of the level, can always be 91 | decompressed using the function fastlz_decompress above. 92 | */ 93 | 94 | int fastlz_compress_level(int level, const void* input, int length, void* output); 95 | 96 | #if defined (__cplusplus) 97 | } 98 | #endif 99 | 100 | #endif /* FASTLZ_H */ 101 | -------------------------------------------------------------------------------- /g_fmt.c: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * 3 | * The author of this software is David M. Gay. 4 | * 5 | * Copyright (c) 1991, 1996 by Lucent Technologies. 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose without fee is hereby granted, provided that this entire notice 9 | * is included in all copies of any software which is or includes a copy 10 | * or modification of this software and in all copies of the supporting 11 | * documentation for such software. 12 | * 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY 15 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 16 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | * 18 | ***************************************************************/ 19 | 20 | /* g_fmt(buf,x) stores the closest decimal approximation to x in buf; 21 | * it suffices to declare buf 22 | * char buf[32]; 23 | */ 24 | 25 | /* Modified for use with php in the memcached client extension. 26 | * 27 | * // Teddy Grenman , 2010-05-18. 28 | */ 29 | 30 | #include 31 | 32 | char *php_memcached_g_fmt(register char *b, double x) { 33 | register int i, k; 34 | register char *s; 35 | int decpt, j; 36 | #if PHP_VERSION_ID < 80100 37 | int sign; 38 | #else 39 | bool sign; 40 | #endif 41 | char *b0, *s0, *se; 42 | 43 | b0 = b; 44 | #ifdef IGNORE_ZERO_SIGN 45 | if (!x) { 46 | *b++ = '0'; 47 | *b = 0; 48 | goto done; 49 | } 50 | #endif 51 | 52 | s = s0 = zend_dtoa(x, 0, 0, &decpt, &sign, &se); 53 | if (sign) 54 | *b++ = '-'; 55 | if (decpt == 9999) /* Infinity or Nan */ { 56 | while((*b++ = *s++)); 57 | goto done0; 58 | } 59 | if (decpt <= -4 || decpt > se - s + 5) { 60 | *b++ = *s++; 61 | if (*s) { 62 | *b++ = '.'; 63 | while((*b = *s++)) 64 | b++; 65 | } 66 | *b++ = 'e'; 67 | /* sprintf(b, "%+.2d", decpt - 1); */ 68 | if (--decpt < 0) { 69 | *b++ = '-'; 70 | decpt = -decpt; 71 | } 72 | else 73 | *b++ = '+'; 74 | for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10); 75 | for(;;) { 76 | i = decpt / k; 77 | *b++ = i + '0'; 78 | if (--j <= 0) 79 | break; 80 | decpt -= i*k; 81 | decpt *= 10; 82 | } 83 | *b = 0; 84 | } else if (decpt <= 0) { 85 | *b++ = '.'; 86 | for(; decpt < 0; decpt++) 87 | *b++ = '0'; 88 | while((*b++ = *s++)); 89 | } else { 90 | while((*b = *s++)) { 91 | b++; 92 | if (--decpt == 0 && *s) 93 | *b++ = '.'; 94 | } 95 | for(; decpt > 0; decpt--) 96 | *b++ = '0'; 97 | *b = 0; 98 | } 99 | 100 | done0: 101 | zend_freedtoa(s0); 102 | #ifdef IGNORE_ZERO_SIGN 103 | done: 104 | #endif 105 | return b0; 106 | } 107 | -------------------------------------------------------------------------------- /g_fmt.h: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * 3 | * The author of this software is David M. Gay. 4 | * 5 | * Copyright (c) 1991, 1996 by Lucent Technologies. 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose without fee is hereby granted, provided that this entire notice 9 | * is included in all copies of any software which is or includes a copy 10 | * or modification of this software and in all copies of the supporting 11 | * documentation for such software. 12 | * 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY 15 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 16 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | * 18 | ***************************************************************/ 19 | 20 | /* g_fmt(buf,x) stores the closest decimal approximation to x in buf; 21 | * it suffices to declare buf 22 | * char buf[32]; 23 | */ 24 | 25 | /* Modified for use with php in the memcached client 26 | * extension by Teddy Grenman, 2010. 27 | */ 28 | 29 | #ifndef MEMC_G_FMT_H 30 | #define MEMC_G_FMT_H 31 | 32 | char *php_memcached_g_fmt(register char *b, double x); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /php_libmemcached_compat.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 2009 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.0 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_0.txt. | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Andrei Zmievski | 14 | +----------------------------------------------------------------------+ 15 | */ 16 | 17 | #include "php_memcached.h" 18 | #include "php_memcached_private.h" 19 | #include "php_libmemcached_compat.h" 20 | 21 | memcached_return php_memcached_exist(memcached_st *memc, zend_string *key) 22 | { 23 | #ifdef HAVE_MEMCACHED_EXIST 24 | return memcached_exist(memc, key->val, key->len); 25 | #else 26 | memcached_return rc = MEMCACHED_SUCCESS; 27 | uint32_t flags = 0; 28 | size_t value_length = 0; 29 | char *value = NULL; 30 | 31 | value = memcached_get(memc, key->val, key->len, &value_length, &flags, &rc); 32 | if (value) { 33 | zend_bool *is_persistent = memcached_get_user_data(memc); 34 | pefree(value, *is_persistent); 35 | } 36 | return rc; 37 | #endif 38 | } 39 | 40 | memcached_return php_memcached_touch(memcached_st *memc, const char *key, size_t key_len, time_t expiration) 41 | { 42 | #if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000018 43 | if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { 44 | php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.18, please use ascii protocol or upgrade libmemcached"); 45 | } 46 | #endif 47 | return memcached_touch(memc, key, key_len, expiration); 48 | } 49 | 50 | memcached_return php_memcached_touch_by_key(memcached_st *memc, const char *server_key, size_t server_key_len, const char *key, size_t key_len, time_t expiration) 51 | { 52 | #if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000018 53 | if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { 54 | php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.18, please use ascii protocol or upgrade libmemcached"); 55 | } 56 | #endif 57 | return memcached_touch_by_key(memc, server_key, server_key_len, key, key_len, expiration); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /php_libmemcached_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 2009 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.0 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_0.txt. | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Andrei Zmievski | 14 | +----------------------------------------------------------------------+ 15 | */ 16 | 17 | #ifndef PHP_LIBMEMCACHED_COMPAT 18 | #define PHP_LIBMEMCACHED_COMPAT 19 | 20 | /* this is the version(s) we support */ 21 | #include 22 | 23 | memcached_return php_memcached_exist (memcached_st *memc, zend_string *key); 24 | 25 | memcached_return php_memcached_touch(memcached_st *memc, const char *key, size_t key_len, time_t expiration); 26 | memcached_return php_memcached_touch_by_key(memcached_st *memc, const char *server_key, size_t server_key_len, const char *key, size_t key_len, time_t expiration); 27 | 28 | #if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000017 29 | typedef const memcached_instance_st * php_memcached_instance_st; 30 | #else 31 | typedef memcached_server_instance_st php_memcached_instance_st; 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /php_memcached.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 2009 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.0 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_0.txt. | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Andrei Zmievski | 14 | +----------------------------------------------------------------------+ 15 | */ 16 | 17 | #ifndef PHP_MEMCACHED_H 18 | #define PHP_MEMCACHED_H 19 | 20 | #include "php.h" 21 | #include "Zend/zend_smart_str.h" 22 | 23 | #ifdef PHP_WIN32 24 | #include "main/config.w32.h" 25 | #else 26 | #include "main/php_config.h" 27 | #endif 28 | 29 | #ifdef HAVE_CONFIG_H 30 | # include "config.h" 31 | #endif 32 | 33 | #define PHP_MEMCACHED_VERSION "3.2.0" 34 | 35 | #if defined(PHP_WIN32) && defined(MEMCACHED_EXPORTS) 36 | #define PHP_MEMCACHED_API __declspec(dllexport) 37 | #else 38 | #define PHP_MEMCACHED_API PHPAPI 39 | #endif 40 | 41 | PHP_MEMCACHED_API zend_class_entry *php_memc_get_ce(void); 42 | PHP_MEMCACHED_API zend_class_entry *php_memc_get_exception(void); 43 | PHP_MEMCACHED_API zend_class_entry *php_memc_get_exception_base(int root); 44 | 45 | extern zend_module_entry memcached_module_entry; 46 | #define phpext_memcached_ptr &memcached_module_entry 47 | 48 | #endif /* PHP_MEMCACHED_H */ 49 | 50 | /* 51 | * Local variables: 52 | * tab-width: 4 53 | * c-basic-offset: 4 54 | * End: 55 | * vim600: noet sw=4 ts=4 fdm=marker 56 | * vim<600: noet sw=4 ts=4 57 | */ 58 | -------------------------------------------------------------------------------- /php_memcached_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 2009-2013 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt. | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Mikko Koppanen | 14 | +----------------------------------------------------------------------+ 15 | */ 16 | 17 | #ifndef _PHP_MEMCACHED_SERVER_H_ 18 | # define _PHP_MEMCACHED_SERVER_H_ 19 | 20 | #ifdef HAVE_MEMCACHED_PROTOCOL 21 | 22 | #include 23 | 24 | /* 25 | Opaque structure 26 | */ 27 | typedef struct _php_memc_proto_handler_t php_memc_proto_handler_t; 28 | 29 | /* 30 | Functions 31 | */ 32 | php_memc_proto_handler_t *php_memc_proto_handler_new (); 33 | 34 | void php_memc_proto_handler_destroy (php_memc_proto_handler_t **ptr); 35 | 36 | zend_bool php_memc_proto_handler_run (php_memc_proto_handler_t *h, zend_string *address); 37 | 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /php_memcached_session.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 2009-2010 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt. | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Andrei Zmievski | 14 | +----------------------------------------------------------------------+ 15 | */ 16 | 17 | #ifndef PHP_MEMCACHED_SESSION_H 18 | #define PHP_MEMCACHED_SESSION_H 19 | 20 | /* session handler struct */ 21 | 22 | #include "ext/session/php_session.h" 23 | 24 | extern ps_module ps_mod_memcached; 25 | #define ps_memcached_ptr &ps_mod_memcached 26 | 27 | PS_FUNCS_UPDATE_TIMESTAMP(memcached); 28 | 29 | PS_OPEN_FUNC(memcached); 30 | PS_CLOSE_FUNC(memcached); 31 | PS_READ_FUNC(memcached); 32 | PS_WRITE_FUNC(memcached); 33 | PS_DESTROY_FUNC(memcached); 34 | PS_GC_FUNC(memcached); 35 | PS_CREATE_SID_FUNC(memcached); 36 | PS_VALIDATE_SID_FUNC(memcached); 37 | PS_UPDATE_TIMESTAMP_FUNC(memcached); 38 | 39 | /* Called from php_memcached.c */ 40 | int php_memc_session_minit(int module_number); 41 | 42 | #endif /* PHP_MEMCACHED_SESSION_H */ 43 | -------------------------------------------------------------------------------- /server-example/run-server.php: -------------------------------------------------------------------------------- 1 | on (Memcached::ON_CONNECT, 6 | function ($remote_addr) { 7 | echo "Incoming connection from {$remote_addr}" . PHP_EOL; 8 | return Memcached::RESPONSE_SUCCESS; 9 | }); 10 | 11 | $server->on (Memcached::ON_ADD, 12 | function ($client_id, $key, $value, $flags, $expiration, &$cas) { 13 | echo "client_id=[$client_id]: Add key=[$key], value=[$value], flags=[$flags], expiration=[$expiration]" . PHP_EOL; 14 | $cas = 15; 15 | return Memcached::RESPONSE_SUCCESS; 16 | }); 17 | 18 | $server->on (Memcached::ON_APPEND, 19 | function ($client_id, $key, $value, $cas, &$result_cas) { 20 | echo "client_id=[$client_id]: Append key=[$key], value=[$value], cas=[$cas]" . PHP_EOL; 21 | return Memcached::RESPONSE_SUCCESS; 22 | }); 23 | 24 | $server->on (Memcached::ON_PREPEND, 25 | function ($client_id, $key, $value, $cas, &$result_cas) { 26 | echo "client_id=[$client_id]: Prepend key=[$key], value=[$value], cas=[$cas]" . PHP_EOL; 27 | return Memcached::RESPONSE_SUCCESS; 28 | }); 29 | 30 | $server->on (Memcached::ON_INCREMENT, 31 | function ($client_id, $key, $delta, $initial, $expiration, &$result, &$result_cas) { 32 | echo "client_id=[$client_id]: Incrementing key=[$key], delta=[$delta], initial=[$initial], expiration=[$expiration]" . PHP_EOL; 33 | return Memcached::RESPONSE_SUCCESS; 34 | }); 35 | 36 | $server->on (Memcached::ON_DECREMENT, 37 | function ($client_id, $key, $delta, $initial, $expiration, &$result, &$result_cas) { 38 | echo "client_id=[$client_id]: Decrementing key=[$key], delta=[$delta], initial=[$initial], expiration=[$expiration]" . PHP_EOL; 39 | return Memcached::RESPONSE_SUCCESS; 40 | }); 41 | 42 | $server->on (Memcached::ON_DELETE, 43 | function ($client_id, $key, $cas) { 44 | echo "client_id=[$client_id]: Delete key=[$key], cas=[$cas]" . PHP_EOL; 45 | return Memcached::RESPONSE_SUCCESS; 46 | }); 47 | 48 | $server->on (Memcached::ON_FLUSH, 49 | function ($client_id, $when) { 50 | echo "client_id=[$client_id]: Flush when=[$when]" . PHP_EOL; 51 | return Memcached::RESPONSE_SUCCESS; 52 | }); 53 | 54 | $server->on (Memcached::ON_GET, 55 | function ($client_id, $key, &$value, &$flags, &$cas) { 56 | echo "client_id=[$client_id]: Get key=[$key]" . PHP_EOL; 57 | $value = "Hello to you client!"; 58 | return Memcached::RESPONSE_SUCCESS; 59 | }); 60 | 61 | $server->on (Memcached::ON_NOOP, 62 | function ($client_id) { 63 | echo "client_id=[$client_id]: Noop" . PHP_EOL; 64 | return Memcached::RESPONSE_SUCCESS; 65 | }); 66 | 67 | $server->on (Memcached::ON_REPLACE, 68 | function ($client_id, $key, $value, $flags, $expiration, $cas, &$result_cas) { 69 | echo "client_id=[$client_id]: Replace key=[$key], value=[$value], flags=[$flags], expiration=[$expiration], cas=[$cas]" . PHP_EOL; 70 | return Memcached::RESPONSE_SUCCESS; 71 | }); 72 | 73 | $server->on (Memcached::ON_SET, 74 | function ($client_id, $key, $value, $flags, $expiration, $cas, &$result_cas) { 75 | echo "client_id=[$client_id]: Set key=[$key], value=[$value], flags=[$flags], expiration=[$expiration], cas=[$cas]" . PHP_EOL; 76 | return Memcached::RESPONSE_SUCCESS; 77 | }); 78 | 79 | $server->on (Memcached::ON_STAT, 80 | function ($client_id, $key, &$value) { 81 | echo "client_id=[$client_id]: Stat key=[$key]" . PHP_EOL; 82 | $value = "Stat reply"; 83 | return Memcached::RESPONSE_SUCCESS; 84 | }); 85 | 86 | $server->on (Memcached::ON_QUIT, 87 | function ($client_id) { 88 | echo "client_id=[$client_id]: Client quit" . PHP_EOL; 89 | return Memcached::RESPONSE_SUCCESS; 90 | }); 91 | 92 | $server->run ("127.0.0.1:3434"); 93 | -------------------------------------------------------------------------------- /server-example/set-get-server.php: -------------------------------------------------------------------------------- 1 | values [$key] = array ('value' => $value, 10 | 'expires' => time () + $expiration); 11 | } 12 | 13 | public function get ($key) { 14 | if (isset ($this->values [$key])) { 15 | if ($this->values [$key] ['expires'] < time ()) { 16 | unset ($this->values [$key]); 17 | return null; 18 | } 19 | return $this->values [$key] ['value']; 20 | } 21 | else 22 | return null; 23 | } 24 | } 25 | 26 | $storage = new Storage (); 27 | 28 | $server->on (Memcached::ON_GET, 29 | function ($client_id, $key, &$value, &$flags, &$cas) use ($storage) { 30 | echo "Getting key=[$key]" . PHP_EOL; 31 | if (($value = $storage->get ($key)) != null) 32 | return Memcached::RESPONSE_SUCCESS; 33 | 34 | return Memcached::RESPONSE_KEY_ENOENT; 35 | }); 36 | 37 | $server->on (Memcached::ON_SET, 38 | function ($client_id, $key, $value, $flags, $expiration, $cas, &$result_cas) use ($storage) { 39 | echo "Setting key=[$key] value=[$value]" . PHP_EOL; 40 | $storage->set ($key, $value, $expiration); 41 | return Memcached::RESPONSE_SUCCESS; 42 | }); 43 | 44 | $server->run ("127.0.0.1:3434"); -------------------------------------------------------------------------------- /server-example/set-get.php: -------------------------------------------------------------------------------- 1 | setOption(Memcached::OPT_BINARY_PROTOCOL, true); 5 | $cache->setOption(Memcached::OPT_COMPRESSION, false); 6 | $cache->addServer('localhost', 3434); 7 | 8 | $cache->set ('set_key1', 'This is the first key', 10); 9 | var_dump ($cache->get ('set_key1')); 10 | 11 | $cache->set ('set_key2', 'This is the second key', 2); 12 | var_dump ($cache->get ('set_key2')); 13 | -------------------------------------------------------------------------------- /server-example/test-server.php: -------------------------------------------------------------------------------- 1 | setOption(Memcached::OPT_BINARY_PROTOCOL, true); 5 | $cache->setOption(Memcached::OPT_COMPRESSION, false); 6 | $cache->addServer('localhost', 3434); 7 | 8 | $cache->add("add_key", "hello", 500); 9 | $cache->append("append_key", "world"); 10 | $cache->prepend("prepend_key", "world"); 11 | 12 | $cache->increment("incr", 2, 1, 500); 13 | $cache->decrement("decr", 2, 1, 500); 14 | 15 | $cache->delete("delete_k"); 16 | $cache->flush(1); 17 | 18 | var_dump ($cache->get ('get_this')); 19 | 20 | $cache->set ('set_key', 'value 1', 100); 21 | $cache->replace ('replace_key', 'value 2', 200); 22 | 23 | $cache->getStats (); 24 | 25 | $cache->quit(); 26 | sleep (1); -------------------------------------------------------------------------------- /tests/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for memcached presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 9 | --EXPECT-- 10 | memcached extension is available 11 | -------------------------------------------------------------------------------- /tests/add.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::add() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete('foo'); 11 | var_dump($m->add('foo', 1, 60)); 12 | var_dump($m->get('foo')); 13 | var_dump($m->add('foo', 2, 60)); 14 | var_dump($m->get('foo')); 15 | 16 | 17 | --EXPECT-- 18 | bool(true) 19 | int(1) 20 | bool(false) 21 | int(1) 22 | -------------------------------------------------------------------------------- /tests/append.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::append() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete('foo'); 12 | $m->setOption(Memcached::OPT_COMPRESSION, true); 13 | var_dump($m->append('foo', 'a')); 14 | echo error_get_last()["message"], "\n"; 15 | 16 | $m->setOption(Memcached::OPT_COMPRESSION, false); 17 | $m->delete('foo'); 18 | var_dump($m->append('foo', 'a')); 19 | var_dump($m->get('foo')); 20 | $m->set('foo', 'a'); 21 | var_dump($m->append('foo', 'b')); 22 | var_dump($m->get('foo')); 23 | 24 | --EXPECTF-- 25 | NULL 26 | %s: cannot append/prepend with compression turned on 27 | bool(false) 28 | bool(false) 29 | bool(true) 30 | string(2) "ab" 31 | -------------------------------------------------------------------------------- /tests/bad_construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached construct with bad arguments 3 | --SKIPIF-- 4 | = 80000) die("skip PHP 7 only"); 7 | ?> 8 | --FILE-- 9 | setOption (Memcached::OPT_BINARY_PROTOCOL, true)); 23 | 24 | echo "OK" . PHP_EOL; 25 | 26 | --EXPECTF-- 27 | Warning: Memcached::__construct() expects parameter 1 to be string, object given in %s on line 3 28 | Memcached::__construct() expects parameter 1 to be string, object given 29 | object(Memcached)#1 (0) { 30 | } 31 | 32 | Warning: Memcached::setOption(): Memcached constructor was not called in %s on line 14 33 | NULL 34 | OK 35 | 36 | -------------------------------------------------------------------------------- /tests/bad_construct_8.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached construct with bad arguments 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | getMessage() . PHP_EOL; 15 | } 16 | 17 | class extended extends Memcached { 18 | public function __construct () { 19 | } 20 | } 21 | 22 | error_reporting(E_ALL); 23 | try { 24 | $extended = new extended (); 25 | var_dump ($extended->setOption (Memcached::OPT_BINARY_PROTOCOL, true)); 26 | } catch (Error $e) { 27 | echo $e->getMessage() . PHP_EOL; 28 | } 29 | 30 | echo "OK" . PHP_EOL; 31 | 32 | --EXPECTF-- 33 | Memcached::__construct(): Argument #1 ($persistent_id) must be of type ?string, stdClass given 34 | Memcached constructor was not called 35 | OK 36 | 37 | -------------------------------------------------------------------------------- /tests/bug_16084.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached: Bug #16084 (Crash when addServers is called with an associative array) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array ( 'KEYHERE' => 'localhost', 11211, 3 ), ); 8 | $m = new memcached(); 9 | var_dump($m->addServers($servers)); 10 | $list = $m->getServerList(); 11 | 12 | var_dump ($list[0]["host"], $list[0]["port"]); 13 | echo "OK"; 14 | 15 | ?> 16 | --EXPECT-- 17 | bool(true) 18 | string(9) "localhost" 19 | int(11211) 20 | OK 21 | -------------------------------------------------------------------------------- /tests/bug_16959.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached: Bug #16959 (getMulti + BINARY_PROTOCOL problem) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | true 10 | )); 11 | 12 | $cache->set('key_0', 'value0'); 13 | $cache->set('key_0_additional', 'value0_additional'); 14 | 15 | // -------------- NORMAL 16 | echo "NORMAL\n"; 17 | $keys = array( 'key_0', 'key_0_additional' ); 18 | $values = $cache->getMulti($keys); 19 | echo $cache->getResultMessage(), "\n"; 20 | echo "Values:\n"; 21 | foreach ($values as $k => $v) { 22 | var_dump($k); 23 | var_dump($v); 24 | var_dump($values[$k]); 25 | } 26 | // --------------- REVERSED KEY ORDER 27 | echo "REVERSED KEY ORDER\n"; 28 | $keys = array( 'key_0_additional', 'key_0' ); 29 | $values = $cache->getMulti($keys); 30 | echo $cache->getResultMessage(), "\n"; 31 | echo "Values:\n"; 32 | foreach ($values as $k => $v) { 33 | var_dump($k); 34 | var_dump($v); 35 | var_dump($values[$k]); 36 | } 37 | 38 | --EXPECT-- 39 | NORMAL 40 | SUCCESS 41 | Values: 42 | string(5) "key_0" 43 | string(6) "value0" 44 | string(6) "value0" 45 | string(16) "key_0_additional" 46 | string(17) "value0_additional" 47 | string(17) "value0_additional" 48 | REVERSED KEY ORDER 49 | SUCCESS 50 | Values: 51 | string(16) "key_0_additional" 52 | string(17) "value0_additional" 53 | string(17) "value0_additional" 54 | string(5) "key_0" 55 | string(6) "value0" 56 | string(6) "value0" 57 | -------------------------------------------------------------------------------- /tests/bug_17137.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Change prefix, pecl bug #17137 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | true, 11 | Memcached::OPT_PREFIX_KEY => 'prefix1', 12 | )); 13 | 14 | $memcache2 = memc_get_instance (array ( 15 | Memcached::OPT_BINARY_PROTOCOL => true, 16 | Memcached::OPT_PREFIX_KEY => 'prefix2', 17 | )); 18 | 19 | var_dump($memcache->getOption(Memcached::OPT_PREFIX_KEY)); 20 | 21 | var_dump($memcache->set('test', "val_prefix1", 120)); 22 | var_dump($memcache->get('test')); 23 | 24 | 25 | var_dump($memcache2->getOption(Memcached::OPT_PREFIX_KEY)); 26 | 27 | var_dump($memcache2->set('test', "val_prefix2", 120)); 28 | var_dump($memcache2->get('test')); 29 | 30 | 31 | var_dump($memcache->get('test')); 32 | --EXPECT-- 33 | string(7) "prefix1" 34 | bool(true) 35 | string(11) "val_prefix1" 36 | string(7) "prefix2" 37 | bool(true) 38 | string(11) "val_prefix2" 39 | string(11) "val_prefix1" 40 | -------------------------------------------------------------------------------- /tests/bug_18639.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getServerByKey(): Bug pecl#18639 (Segfault in getServerByKey) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set('test', 'test1')); 11 | var_dump($m->getServerByKey('1')); 12 | 13 | --EXPECTF-- 14 | bool(true) 15 | array(3) { 16 | ["host"]=> 17 | string(9) "%s" 18 | ["port"]=> 19 | int(%d) 20 | ["weight"]=> 21 | int(%r[01]%r) 22 | } 23 | -------------------------------------------------------------------------------- /tests/cachecallback.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::get() with cache callback 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete($first_key); 17 | $m->delete($second_key); 18 | $m->delete($third_key); 19 | 20 | var_dump ( 21 | $m->get ($first_key, function (Memcached $memc, $key, &$value, &$expiration) { 22 | $value = "hello"; 23 | $expiration = 10; 24 | return true; 25 | }) 26 | ); 27 | 28 | var_dump ($m->get ($first_key)); 29 | 30 | var_dump ( 31 | $m->get ($second_key, function (Memcached $memc, $key, &$value, &$expiration) { 32 | $value = "hello"; 33 | $expiration = 10; 34 | return false; 35 | }) 36 | ); 37 | 38 | var_dump ($m->get ($second_key)); 39 | 40 | try { 41 | $m->get ($third_key, function (Memcached $memc, $key, &$value, &$expiration) { 42 | $value = "hello"; 43 | $expiration = 10; 44 | throw new Exception ('this is a test'); 45 | return true; 46 | }); 47 | } catch (Exception $e) { 48 | echo 'Got exception' . PHP_EOL; 49 | } 50 | 51 | var_dump ($m->get ($third_key)); 52 | 53 | 54 | echo "OK" . PHP_EOL; 55 | 56 | --EXPECT-- 57 | string(5) "hello" 58 | string(5) "hello" 59 | bool(false) 60 | bool(false) 61 | Got exception 62 | bool(false) 63 | OK -------------------------------------------------------------------------------- /tests/callback_exception.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | make sure that callback exception behaves correctly 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 49 | --EXPECT-- 50 | success 51 | success 52 | empty_cb called 53 | success 54 | OK 55 | -------------------------------------------------------------------------------- /tests/callback_exception_2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Callback initializer throws and dies 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | isPersistent()); 11 | throw new RuntimeException('Cb exception'); 12 | } 13 | 14 | function init_cb_die($m, $id) { 15 | echo "ran quitting cb\n"; 16 | die("quit in cb"); 17 | } 18 | 19 | error_reporting(0); 20 | 21 | echo "cb with exception\n"; 22 | try { 23 | $m1 = new Memcached(null, 'init_cb'); 24 | } catch (RuntimeException $e) { 25 | echo $e->getMessage(), "\n"; 26 | } 27 | 28 | echo "cb persistent with exception\n"; 29 | try { 30 | $m2 = new Memcached('foo', 'init_cb'); 31 | } catch (RuntimeException $e) { 32 | echo $e->getMessage(), "\n"; 33 | } 34 | 35 | echo "cb persistent dies\n"; 36 | try { 37 | $m3 = new Memcached('bar', 'init_cb_die'); 38 | } catch (RuntimeException $e) { 39 | echo $e->getMessage(), "\n"; 40 | } 41 | echo "not run\n"; 42 | 43 | --EXPECT-- 44 | cb with exception 45 | ran throwing cb 46 | bool(false) 47 | Cb exception 48 | cb persistent with exception 49 | ran throwing cb 50 | bool(true) 51 | Cb exception 52 | cb persistent dies 53 | ran quitting cb 54 | quit in cb 55 | -------------------------------------------------------------------------------- /tests/cas.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached fetch cas & set cas 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete('cas_test'); 11 | 12 | $m->set('cas_test', 'hello'); 13 | $cas_token = $m->get('cas_test', null, Memcached::GET_EXTENDED)['cas']; 14 | 15 | $v = $m->cas($cas_token, 'cas_test', 0); 16 | if ($v != true) { 17 | echo "CAS failed"; 18 | } 19 | 20 | echo "OK\n"; 21 | ?> 22 | --EXPECT-- 23 | OK -------------------------------------------------------------------------------- /tests/cas_multi.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached multi fetch cas & set cas 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 12 | 'cas_test_2' => 2, 13 | ); 14 | 15 | foreach ($data as $key => $v) { 16 | $m->delete($key); 17 | } 18 | 19 | $m->setMulti($data, 10); 20 | $actual = $m->getMulti(array_keys($data), Memcached::GET_EXTENDED); 21 | 22 | foreach ($actual as $key => $v) { 23 | if (is_null($v['cas'])) { 24 | echo "missing cas token(s)\n"; 25 | echo "data: "; 26 | var_dump($data); 27 | echo "actual data: "; 28 | var_dump($actual); 29 | return; 30 | } 31 | 32 | $v = $m->cas($v['cas'], $key, 11); 33 | if (!$v) { 34 | echo "Error setting key: $key value: 11 with CAS: ", $v['cas'], "\n"; 35 | return; 36 | } 37 | $v = $m->get($key); 38 | if ($v !== 11) { 39 | echo "Wanted $key to be 11, value is: "; 40 | var_dump($v); 41 | return; 42 | } 43 | } 44 | 45 | if (array_keys($actual) !== array_keys($data)) { 46 | echo "missing value(s)\n"; 47 | echo "data :"; 48 | var_dump($data); 49 | echo "actual data: "; 50 | var_dump($actual); 51 | return; 52 | } 53 | 54 | echo "OK\n"; 55 | 56 | ?> 57 | --EXPECT-- 58 | OK -------------------------------------------------------------------------------- /tests/check_if_persistent.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check if persistent object is persistent 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | setOption(Memcached::OPT_PREFIX_KEY, "foo_"); 10 | 11 | var_dump($m1->isPersistent()); 12 | 13 | $m1 = new Memcached('id1'); 14 | var_dump($m1->isPersistent()); 15 | 16 | $m2 = new Memcached('id1'); 17 | var_dump($m2->isPersistent()); 18 | // this change affects $m1 19 | $m2->setOption(Memcached::OPT_PREFIX_KEY, "bar_"); 20 | 21 | $m3 = new Memcached('id2'); 22 | var_dump($m3->isPersistent()); 23 | 24 | $m3 = new Memcached(); 25 | var_dump($m3->isPersistent()); 26 | 27 | // objects have the same resource, but they are not the same object. 28 | var_dump($m1 === $m2); 29 | var_dump($m1->getOption(Memcached::OPT_PREFIX_KEY)); 30 | --EXPECT-- 31 | bool(true) 32 | bool(true) 33 | bool(true) 34 | bool(true) 35 | bool(false) 36 | bool(false) 37 | string(4) "bar_" 38 | -------------------------------------------------------------------------------- /tests/check_if_pristine.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check if persistent object is new or an old persistent one 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | setOption(Memcached::OPT_PREFIX_KEY, "foo_"); 10 | 11 | var_dump($m1->isPristine()); 12 | 13 | $m1 = new Memcached('id1'); 14 | var_dump($m1->isPristine()); 15 | 16 | $m2 = new Memcached('id1'); 17 | var_dump($m2->isPristine()); 18 | // this change affects $m1 19 | $m2->setOption(Memcached::OPT_PREFIX_KEY, "bar_"); 20 | 21 | $m3 = new Memcached('id2'); 22 | var_dump($m3->isPristine()); 23 | 24 | $m3 = new Memcached(); 25 | var_dump($m3->isPristine()); 26 | --EXPECT-- 27 | bool(true) 28 | bool(false) 29 | bool(false) 30 | bool(true) 31 | bool(true) 32 | -------------------------------------------------------------------------------- /tests/check_key.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::checkKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | false, 10 | Memcached::OPT_VERIFY_KEY => true 11 | )); 12 | 13 | $keys = [ 14 | 'foo', 15 | 'foo bar', 16 | str_repeat('a',65), 17 | str_repeat('b',250), 18 | str_repeat('c',251), 19 | 'Montréal', 20 | 'København', 21 | 'Düsseldorf', 22 | 'Kraków', 23 | 'İstanbul', 24 | 'ﺎﺨﺘﺑﺍﺭ PHP', 25 | '測試', 26 | 'Тестирование', 27 | 'پی ایچ پی کی جانچ ہو رہی ہے', 28 | 'Testataan PHP: tä', 29 | 'Að prófa PHP', 30 | 'د پی ایچ پی ازمول', 31 | 'Pruvà PHP' 32 | ]; 33 | foreach($keys as $key) { 34 | echo "Checking \"$key\"" . PHP_EOL; 35 | echo "MEMC_CHECK_KEY: "; 36 | var_dump($m->checkKey($key)); 37 | echo "libmemcached: "; 38 | var_dump($m->set($key, "this is a test")); 39 | var_dump($m->getResultMessage()); 40 | echo "\n"; 41 | } 42 | --EXPECT-- 43 | Checking "foo" 44 | MEMC_CHECK_KEY: bool(true) 45 | libmemcached: bool(true) 46 | string(7) "SUCCESS" 47 | 48 | Checking "foo bar" 49 | MEMC_CHECK_KEY: bool(false) 50 | libmemcached: bool(false) 51 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 52 | 53 | Checking "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 54 | MEMC_CHECK_KEY: bool(true) 55 | libmemcached: bool(true) 56 | string(7) "SUCCESS" 57 | 58 | Checking "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" 59 | MEMC_CHECK_KEY: bool(true) 60 | libmemcached: bool(true) 61 | string(7) "SUCCESS" 62 | 63 | Checking "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" 64 | MEMC_CHECK_KEY: bool(false) 65 | libmemcached: bool(false) 66 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 67 | 68 | Checking "Montréal" 69 | MEMC_CHECK_KEY: bool(false) 70 | libmemcached: bool(false) 71 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 72 | 73 | Checking "København" 74 | MEMC_CHECK_KEY: bool(false) 75 | libmemcached: bool(false) 76 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 77 | 78 | Checking "Düsseldorf" 79 | MEMC_CHECK_KEY: bool(false) 80 | libmemcached: bool(false) 81 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 82 | 83 | Checking "Kraków" 84 | MEMC_CHECK_KEY: bool(false) 85 | libmemcached: bool(false) 86 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 87 | 88 | Checking "İstanbul" 89 | MEMC_CHECK_KEY: bool(false) 90 | libmemcached: bool(false) 91 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 92 | 93 | Checking "ﺎﺨﺘﺑﺍﺭ PHP" 94 | MEMC_CHECK_KEY: bool(false) 95 | libmemcached: bool(false) 96 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 97 | 98 | Checking "測試" 99 | MEMC_CHECK_KEY: bool(false) 100 | libmemcached: bool(false) 101 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 102 | 103 | Checking "Тестирование" 104 | MEMC_CHECK_KEY: bool(false) 105 | libmemcached: bool(false) 106 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 107 | 108 | Checking "پی ایچ پی کی جانچ ہو رہی ہے" 109 | MEMC_CHECK_KEY: bool(false) 110 | libmemcached: bool(false) 111 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 112 | 113 | Checking "Testataan PHP: tä" 114 | MEMC_CHECK_KEY: bool(false) 115 | libmemcached: bool(false) 116 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 117 | 118 | Checking "Að prófa PHP" 119 | MEMC_CHECK_KEY: bool(false) 120 | libmemcached: bool(false) 121 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 122 | 123 | Checking "د پی ایچ پی ازمول" 124 | MEMC_CHECK_KEY: bool(false) 125 | libmemcached: bool(false) 126 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 127 | 128 | Checking "Pruvà PHP" 129 | MEMC_CHECK_KEY: bool(false) 130 | libmemcached: bool(false) 131 | string(46) "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE" 132 | 133 | -------------------------------------------------------------------------------- /tests/clone.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test cloning 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | setOption(Memcached::OPT_COMPRESSION, false); 30 | } else { 31 | $m->setOption(Memcached::OPT_COMPRESSION, true); 32 | $m->setOption(Memcached::OPT_COMPRESSION_TYPE, get_compression($set_compression)); 33 | } 34 | 35 | $m->set($key, $value, 1800); 36 | 37 | if (!$get_compression) { 38 | $m->setOption(Memcached::OPT_COMPRESSION, true); 39 | } else { 40 | $m->setOption(Memcached::OPT_COMPRESSION, true); 41 | $m->setOption(Memcached::OPT_COMPRESSION_TYPE, get_compression($get_compression)); 42 | } 43 | 44 | $value_back = $m->get($key); 45 | var_dump($value === $value_back); 46 | } 47 | 48 | fetch_with_compression($m, 'hello1', $data, 'zlib', 'zlib'); 49 | fetch_with_compression($m, 'hello2', $data, 'zlib', 'fastlz'); 50 | fetch_with_compression($m, 'hello3', $data, 'fastlz', 'fastlz'); 51 | fetch_with_compression($m, 'hello4', $data, 'fastlz', 'zlib'); 52 | fetch_with_compression($m, 'hello5', $data, '', 'zlib'); 53 | fetch_with_compression($m, 'hello6', $data, '', 'fastlz'); 54 | fetch_with_compression($m, 'hello7', $data, 'zlib', ''); 55 | fetch_with_compression($m, 'hello8', $data, 'fastlz', ''); 56 | fetch_with_compression($m, 'hello9', $data, '', ''); 57 | ?> 58 | --EXPECT-- 59 | set=[zlib] get=[zlib] 60 | bool(true) 61 | set=[zlib] get=[fastlz] 62 | bool(true) 63 | set=[fastlz] get=[fastlz] 64 | bool(true) 65 | set=[fastlz] get=[zlib] 66 | bool(true) 67 | set=[] get=[zlib] 68 | bool(true) 69 | set=[] get=[fastlz] 70 | bool(true) 71 | set=[zlib] get=[] 72 | bool(true) 73 | set=[fastlz] get=[] 74 | bool(true) 75 | set=[] get=[] 76 | bool(true) 77 | -------------------------------------------------------------------------------- /tests/conf_persist.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Conf settings persist. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'php' 10 | ), 'id1'); 11 | 12 | $m1->set('foo', 'bar'); 13 | 14 | for ($i = 1000; $i > 0; $i--) { 15 | $m1 = new Memcached('id1'); 16 | $rv = $m1->get('foo'); 17 | if ($rv !== 'bar') { 18 | echo "Expected bar got:"; 19 | var_dump($rv); 20 | die(); 21 | } 22 | 23 | $prefix = $m1->getOption(Memcached::OPT_PREFIX_KEY); 24 | if ($prefix !== 'php') { 25 | echo "Expected prefix php got:"; 26 | var_dump($prefix); 27 | die(); 28 | } 29 | } 30 | 31 | echo "OK\n"; 32 | 33 | ?> 34 | --EXPECT-- 35 | OK -------------------------------------------------------------------------------- /tests/config.inc: -------------------------------------------------------------------------------- 1 | setOptions ($opts) == false) 28 | echo "Failed to set options" . PHP_EOL; 29 | 30 | $memcached->addServer($host, $port); 31 | if ($memcached->flush() === false) { 32 | return NULL; 33 | } 34 | return $memcached; 35 | } 36 | 37 | function memc_get_instance (array $opts = array (), $persistent_id = null) 38 | { 39 | return memc_create_instance(MEMC_SERVER_HOST, MEMC_SERVER_PORT, $opts, $persistent_id); 40 | } 41 | 42 | function memc_get_sasl_instance (array $opts = array (), $persistent_id = null) 43 | { 44 | return memc_create_instance(MEMC_SASL_SERVER_HOST, MEMC_SASL_SERVER_PORT, $opts, $persistent_id); 45 | 46 | } 47 | 48 | function memc_get_tls_instance (array $opts = array (), $persistent_id = null) 49 | { 50 | $memcached = new Memcached($persistent_id); 51 | if ($memcached->setOptions ($opts) == false) { 52 | echo "memc_get_tls_instance(): Failed to set options" . PHP_EOL; 53 | } 54 | $memcached->addServer(MEMC_TLS_SERVER_HOST, MEMC_TLS_SERVER_PORT); 55 | return $memcached; 56 | } 57 | 58 | function memc_run_test ($test_function, $options = array ()) 59 | { 60 | foreach ($options as $option_set) { 61 | $memc = memc_get_instance ($option_set ['options']); 62 | $test_function ($memc, $option_set); 63 | } 64 | echo "TEST DONE" . PHP_EOL; 65 | } 66 | 67 | function memc_create_combinations ($name, $serializer, $ignore_object_type = false) 68 | { 69 | return array ( 70 | array ( 71 | 'title' => "$name serializer, ascii protocol", 72 | 'options' => array ( 73 | Memcached::OPT_SERIALIZER => $serializer 74 | ), 75 | 'ignore_object_type' => $ignore_object_type 76 | ), 77 | array ( 78 | 'title' => "$name serializer, binary protocol", 79 | 'options' => array ( 80 | Memcached::OPT_BINARY_PROTOCOL => true, 81 | Memcached::OPT_SERIALIZER => $serializer 82 | ), 83 | 'ignore_object_type' => $ignore_object_type 84 | ), 85 | ); 86 | } 87 | 88 | function memc_get_version($memc) { 89 | $version = $memc->getVersion(); 90 | return array_pop($version); 91 | } 92 | -------------------------------------------------------------------------------- /tests/construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached constructor 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 10 | --EXPECT-- 11 | Memcached 12 | -------------------------------------------------------------------------------- /tests/construct_persistent.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | persistent memcached connection 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setOption(Memcached::OPT_PREFIX_KEY, 'php'); 9 | var_dump($m1->getOption(Memcached::OPT_PREFIX_KEY)); 10 | 11 | $m2 = new Memcached('id1'); 12 | var_dump($m1->getOption(Memcached::OPT_PREFIX_KEY)); 13 | 14 | $m3 = new Memcached(); 15 | var_dump($m3->getOption(Memcached::OPT_PREFIX_KEY)); 16 | ?> 17 | --EXPECT-- 18 | string(3) "php" 19 | string(3) "php" 20 | string(0) "" 21 | -------------------------------------------------------------------------------- /tests/default_behavior.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Default behaviors 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getOption(Memcached::OPT_DISTRIBUTION) == Memcached::DISTRIBUTION_MODULA); 10 | var_dump ($m->getOption(Memcached::OPT_BINARY_PROTOCOL) == false); 11 | var_dump ($m->getOption(Memcached::OPT_CONNECT_TIMEOUT) != 0); 12 | 13 | ini_set('memcached.default_consistent_hash', true); 14 | ini_set('memcached.default_binary_protocol', true); 15 | ini_set('memcached.default_connect_timeout', 1212); 16 | 17 | $m = new Memcached(); 18 | var_dump ($m->getOption(Memcached::OPT_DISTRIBUTION) == Memcached::DISTRIBUTION_CONSISTENT); 19 | var_dump ($m->getOption(Memcached::OPT_BINARY_PROTOCOL) == true); 20 | var_dump ($m->getOption(Memcached::OPT_CONNECT_TIMEOUT) == 1212); 21 | 22 | echo "OK"; 23 | 24 | ?> 25 | --EXPECT-- 26 | bool(true) 27 | bool(true) 28 | bool(true) 29 | bool(true) 30 | bool(true) 31 | bool(true) 32 | OK 33 | -------------------------------------------------------------------------------- /tests/deleted.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached store & fetch type correctness 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set('eisaleeoo', "foo"); 11 | $m->delete('eisaleeoo'); 12 | $v = $m->get('eisaleeoo'); 13 | 14 | if ($v !== Memcached::GET_ERROR_RETURN_VALUE) { 15 | echo "Wanted: "; 16 | var_dump(Memcached::GET_ERROR_RETURN_VALUE); 17 | echo "Got: "; 18 | var_dump($v); 19 | } 20 | 21 | echo "OK\n"; 22 | 23 | ?> 24 | --EXPECT-- 25 | OK -------------------------------------------------------------------------------- /tests/deletemulti.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Delete multi 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'foo-data', 24 | 'bar' => 'bar-data', 25 | 'baz' => 'baz-data', 26 | 'lol' => 'lol-data', 27 | 'kek' => 'kek-data', 28 | ); 29 | 30 | $keys = array_keys($data); 31 | 32 | $null = null; 33 | $m->setMulti($data, 3600); 34 | 35 | /* Check that all keys were stored */ 36 | var_dump(has_all_keys($keys, $m->getMulti($keys))); 37 | 38 | /* Check that all keys get deleted */ 39 | $deleted = $m->deleteMulti($keys); 40 | var_dump(has_all_keys($keys, $deleted, true)); 41 | 42 | /* Try to get the deleted keys, should give empty array */ 43 | var_dump($m->getMulti($keys)); 44 | 45 | /* ---- same tests for byKey variants ---- */ 46 | $m->setMultiByKey("hi", $data, 3600); 47 | 48 | var_dump(has_all_keys($keys, $m->getMultiByKey('hi', $keys))); 49 | 50 | /* Check that all keys get deleted */ 51 | $deleted = $m->deleteMultiByKey('hi', $keys); 52 | var_dump(has_all_keys($keys, $deleted, true)); 53 | 54 | /* Try to get the deleted keys, should give empty array */ 55 | var_dump($m->getMultiByKey('hi', $keys)); 56 | 57 | /* Test deleting non-existent keys */ 58 | $keys = array(); 59 | $keys[] = "nothere"; 60 | $keys[] = "nothere2"; 61 | 62 | $retval = $m->deleteMulti($keys); 63 | 64 | foreach ($retval as $key => $value) { 65 | if ($value === Memcached::RES_NOTFOUND) { 66 | echo "$key NOT FOUND\n"; 67 | } 68 | } 69 | 70 | 71 | ?> 72 | --EXPECT-- 73 | bool(true) 74 | bool(true) 75 | array(0) { 76 | } 77 | bool(true) 78 | bool(true) 79 | array(0) { 80 | } 81 | nothere NOT FOUND 82 | nothere2 NOT FOUND -------------------------------------------------------------------------------- /tests/deletemultitypes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Delete multi key types 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | deleteMulti($keys); 18 | array_walk($keys, 'dump_types'); 19 | 20 | ?> 21 | --EXPECT-- 22 | integer 23 | string 24 | integer 25 | string -------------------------------------------------------------------------------- /tests/experimental/add_bykey.phpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/d1b6afd66ad97d4e93220647e9b7ad23ef130154/tests/experimental/add_bykey.phpt -------------------------------------------------------------------------------- /tests/experimental/addserver_unixdomain.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::addServer() unix doamin socket 3 | --SKIPIF-- 4 | 5 | --CLEAN-- 6 | setOption(Memcached::OPT_CONNECT_TIMEOUT, 1); 14 | $m->setOption(Memcached::OPT_SEND_TIMEOUT, 1); 15 | $m->setOption(Memcached::OPT_RECV_TIMEOUT, 1); 16 | $m->addServer('/tmp/memc_test_unix_socket', 11211, 1); 17 | 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /tests/experimental/append_bykey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::appendByKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setOption(Memcached::OPT_COMPRESSION, false); 10 | 11 | var_dump($m->setByKey('foo', 'foo', 'bar', 10)); 12 | echo $m->getResultMessage(), "\n"; 13 | var_dump($m->appendByKey('foo', 'foo', 'baz')); 14 | echo $m->getResultMessage(), "\n"; 15 | var_dump($m->getByKey('foo', 'foo')); 16 | 17 | --EXPECT-- 18 | bool(true) 19 | SUCCESS 20 | bool(true) 21 | SUCCESS 22 | string(6) "barbaz" 23 | -------------------------------------------------------------------------------- /tests/experimental/cas_bykey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::casByKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete('cas_test'); 11 | 12 | $m->setByKey('keffe', 'cas_test', 10); 13 | $v = $m->getbyKey('keffe', 'cas_test', null, Memcached::GET_EXTENDED); 14 | 15 | $cas_token = $v["cas"]; 16 | if (empty($cas_token)) { 17 | echo "Null cas token for key: cas_test value: 10\n"; 18 | return; 19 | } 20 | 21 | $v = $m->casByKey($cas_token, 'keffe', 'cas_test', 11); 22 | if (!$v) { 23 | echo "Error setting key: cas_test value: 11 with CAS: $cas_token\n"; 24 | return; 25 | } 26 | 27 | $v = $m->getByKey('keffe', 'cas_test'); 28 | 29 | if ($v !== 11) { 30 | echo "Wanted cas_test to be 11, value is: "; 31 | var_dump($v); 32 | } 33 | ?> 34 | --EXPECT-- 35 | -------------------------------------------------------------------------------- /tests/experimental/cas_invalid_key.phpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/d1b6afd66ad97d4e93220647e9b7ad23ef130154/tests/experimental/cas_invalid_key.phpt -------------------------------------------------------------------------------- /tests/experimental/delete_bykey.phpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/d1b6afd66ad97d4e93220647e9b7ad23ef130154/tests/experimental/delete_bykey.phpt -------------------------------------------------------------------------------- /tests/experimental/deletemulti_nonstringkeys.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Delete multi with integer keys 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | '1-data', 12 | 2 => '2-data', 13 | 'foo' => 'foo-data', 14 | 3 => '3-data', 15 | 4 => '4-data', 16 | 'kek' => 'kek-data', 17 | ); 18 | 19 | $str_keys = array_map('strval', array_keys($data)); 20 | 21 | echo "set: "; 22 | $f = true; 23 | foreach ($data as $key => $value) { 24 | $f = $m->set(strval($key), $value, 2) && $f; 25 | } 26 | echo var_dump($f); 27 | 28 | $data[5] = 'not-there'; 29 | 30 | echo "delete: "; 31 | var_dump($m->deleteMulti(array_keys($data))); 32 | echo "Should be empty / not found: "; 33 | var_dump($m->getMulti($str_keys)); 34 | 35 | --EXPECTF-- 36 | set: bool(true) 37 | delete: array(7) { 38 | [1]=> 39 | bool(true) 40 | [2]=> 41 | bool(true) 42 | ["foo"]=> 43 | bool(true) 44 | [3]=> 45 | bool(true) 46 | [4]=> 47 | bool(true) 48 | ["kek"]=> 49 | bool(true) 50 | [5]=> 51 | int(%d) 52 | } 53 | Should be empty / not found: array(0) { 54 | } 55 | -------------------------------------------------------------------------------- /tests/experimental/extreme_floats.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extreme floats: max, min, Inf, -Inf, and NaN 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set('float_inf', INF); 11 | $m->set('float_ninf', -INF); 12 | $m->set('float_nan', NAN); 13 | $m->set('float_big', -1.79769e308); 14 | $m->set('float_small', -2.225e-308); 15 | $m->set('float_subsmall', -4.9406564584125e-324); 16 | var_dump($m->get('float_inf')); 17 | var_dump($m->get('float_ninf')); 18 | var_dump($m->get('float_nan')); 19 | var_dump($m->get('float_big')); 20 | var_dump($m->get('float_small')); 21 | var_dump($m->get('float_subsmall')); 22 | 23 | --EXPECT-- 24 | float(INF) 25 | float(-INF) 26 | float(NAN) 27 | float(-1.79769E+308) 28 | float(-2.225E-308) 29 | float(-5.0E-324) 30 | -------------------------------------------------------------------------------- /tests/experimental/fetch.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached getDelayed() and fetch() with and without cas 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'foo-data', 41 | 'bar' => 'bar-data', 42 | 'baz' => 'baz-data', 43 | 'lol' => 'lol-data', 44 | 'kek' => 'kek-data', 45 | ); 46 | 47 | foreach ($data as $k => $v) { 48 | $m->set($k, $v, 3600); 49 | } 50 | 51 | echo "fetch empty\n"; 52 | var_dump($m->getDelayed(array(), false)); 53 | 54 | echo "fetch loop\n"; 55 | $m->getDelayed(array_keys($data), false); 56 | $tmp = array(); 57 | while ($item = $m->fetch()) $tmp[] = $item; 58 | simple_compare($data, $tmp, false); 59 | 60 | echo "fetch loop with cas\n"; 61 | $m->getDelayed(array_keys($data), true); 62 | $tmp = array(); 63 | while ($item = $m->fetch()) $tmp[] = $item; 64 | simple_compare($data, $tmp, true); 65 | 66 | echo "fetchAll\n"; 67 | $m->getDelayed(array_keys($data), false); 68 | $tmp = $m->fetchAll(); 69 | simple_compare($data, $tmp, false); 70 | 71 | echo "fetchAll with cas\n"; 72 | $m->getDelayed(array_keys($data), true); 73 | $tmp = $m->fetchAll(); 74 | simple_compare($data, $tmp, true); 75 | --EXPECT-- 76 | fetch empty 77 | bool(false) 78 | fetch loop 79 | fetch loop with cas 80 | fetchAll 81 | fetchAll with cas 82 | -------------------------------------------------------------------------------- /tests/experimental/fetch_badunserialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::fetch() with bad unserialize 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | serialize_throws) { 15 | throw new Exception("12"); 16 | } 17 | return array(); 18 | } 19 | 20 | public function __wakeup() { 21 | throw new Exception("1234567890"); 22 | } 23 | 24 | public function serialize() { 25 | if ($this->serialize_throws) { 26 | throw new Exception("1234"); 27 | } 28 | return "1234"; 29 | } 30 | 31 | public function unserialize($str) { 32 | throw new Exception("123456"); 33 | } 34 | } 35 | 36 | $data = new Foo(); 37 | 38 | $m->set('foo', $data, 10); 39 | 40 | error_reporting(0); 41 | var_dump($m->getDelayed(array('foo'), false)); 42 | try { 43 | var_dump($m->fetch()); 44 | } catch (Exception $e) { 45 | echo error_get_last()["message"], "\n"; 46 | echo $e->getMessage(), "\n"; 47 | } 48 | 49 | --EXPECTF-- 50 | bool(true) 51 | Memcached::%s(): could not unserialize value%S 52 | 123456 53 | -------------------------------------------------------------------------------- /tests/experimental/fetchall_badunserialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::fetch() with bad unserialize 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | serialize_throws) { 15 | throw new Exception("12"); 16 | } 17 | return array(); 18 | } 19 | 20 | public function __wakeup() { 21 | throw new Exception("1234567890"); 22 | } 23 | 24 | public function serialize() { 25 | if ($this->serialize_throws) { 26 | throw new Exception("1234"); 27 | } 28 | return "1234"; 29 | } 30 | 31 | public function unserialize($str) { 32 | throw new Exception("123456"); 33 | } 34 | } 35 | 36 | $data = new Foo(); 37 | 38 | $m->set('foo', $data, 10); 39 | 40 | error_reporting(0); 41 | var_dump($m->getDelayed(array('foo'), false)); 42 | try { 43 | var_dump($m->fetchAll()); 44 | } catch (Exception $e) { 45 | echo error_get_last()["message"], "\n"; 46 | echo $e->getMessage(), "\n"; 47 | } 48 | 49 | --EXPECTF-- 50 | bool(true) 51 | Memcached::%s(): could not unserialize value%S 52 | 123456 53 | -------------------------------------------------------------------------------- /tests/experimental/get.phpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/d1b6afd66ad97d4e93220647e9b7ad23ef130154/tests/experimental/get.phpt -------------------------------------------------------------------------------- /tests/experimental/get_bykey.phpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/d1b6afd66ad97d4e93220647e9b7ad23ef130154/tests/experimental/get_bykey.phpt -------------------------------------------------------------------------------- /tests/experimental/get_bykey_cas.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getByKey() with CAS 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set('foo', 1, 10); 17 | 18 | $cas = 0.0; 19 | var_dump($m->getByKey('foo', 'foo', null, $cas)); 20 | var_dump($cas); 21 | echo $m->getResultMessage(), "\n"; 22 | 23 | $cas = 0.0; 24 | var_dump($m->getByKey('', 'foo', null, $cas)); 25 | var_dump($cas); 26 | echo $m->getResultMessage(), "\n"; 27 | 28 | $m->set('bar', "asdf", 10); 29 | 30 | $cas = 0.0; 31 | var_dump($m->getByKey('foo', 'bar', null, $cas)); 32 | var_dump($cas); 33 | echo $m->getResultMessage(), "\n"; 34 | 35 | $m->delete('foo'); 36 | $cas = 0.0; 37 | var_dump($m->getByKey(' � foo jkh a s ���', 'foo', null, $cas)); 38 | var_dump($cas); 39 | echo $m->getResultMessage(), "\n"; 40 | 41 | $cas = 0.0; 42 | var_dump($m->getByKey(' � foo jkh a s ���', '', null, $cas)); 43 | echo $m->getResultMessage(), "\n"; 44 | 45 | $m->delete('foo'); 46 | $cas = 0.0; 47 | var_dump($m->getByKey('foo', 'foo', 'the_callback', $cas)); 48 | var_dump($cas); 49 | var_dump($m->getByKey('foo', 'foo')); 50 | --EXPECTF-- 51 | int(1) 52 | float(%d) 53 | SUCCESS 54 | int(1) 55 | float(%d) 56 | SUCCESS 57 | string(4) "asdf" 58 | float(%d) 59 | SUCCESS 60 | bool(false) 61 | float(0) 62 | NOT FOUND 63 | bool(false) 64 | A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE 65 | called 66 | string(4) "1234" 67 | float(0) 68 | string(4) "1234" 69 | -------------------------------------------------------------------------------- /tests/experimental/get_udp.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::set()/delete() UDP 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setOption(Memcached::OPT_USE_UDP, true); 12 | $m_udp->addServer('127.0.0.1', 11211, 1); 13 | 14 | 15 | 16 | error_reporting(0); 17 | 18 | echo "\n"; 19 | echo "Delete not found\n"; 20 | $m->delete('foo'); 21 | var_dump($m_udp->delete('foo')); 22 | echo $m_udp->getResultMessage(), "\n"; 23 | 24 | echo "\n"; 25 | echo "Set\n"; 26 | var_dump($m_udp->set('foo', "asdf", 10)); 27 | sleep (1); 28 | 29 | echo $m_udp->getResultMessage(), "\n"; 30 | var_dump($m->get('foo')); 31 | 32 | echo "\n"; 33 | echo "Delete found\n"; 34 | var_dump($m_udp->delete('foo')); 35 | sleep (1); 36 | 37 | echo $m_udp->getResultMessage(), "\n"; 38 | $m->get('foo'); 39 | echo $m->getResultMessage(), "\n"; 40 | 41 | 42 | --EXPECT-- 43 | Delete not found 44 | bool(true) 45 | SUCCESS 46 | 47 | Set 48 | bool(true) 49 | SUCCESS 50 | string(4) "asdf" 51 | 52 | Delete found 53 | bool(true) 54 | SUCCESS 55 | NOT FOUND 56 | -------------------------------------------------------------------------------- /tests/experimental/getdelayed_badserver.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getDelayedByKey() with bad server 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addServer('localhost', 48813, 1); 9 | 10 | $data = array( 11 | 'foo' => 'foo-data', 12 | 'bar' => 'bar-data', 13 | 'baz' => 'baz-data', 14 | 'lol' => 'lol-data', 15 | 'kek' => 'kek-data', 16 | ); 17 | 18 | function myfunc() { 19 | $datas = func_get_args(); 20 | var_dump($datas); 21 | } 22 | 23 | $m->getDelayedByKey('kef', array_keys($data), false, 'myfunc'); 24 | 25 | --EXPECT-- 26 | -------------------------------------------------------------------------------- /tests/experimental/getdelayed_badunserialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getDelayed() with bad unserialize 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | serialize_throws) { 15 | throw new Exception("12"); 16 | } 17 | return array(); 18 | } 19 | 20 | public function __wakeup() { 21 | throw new Exception("1234567890"); 22 | } 23 | 24 | public function serialize() { 25 | if ($this->serialize_throws) { 26 | throw new Exception("1234"); 27 | } 28 | return "1234"; 29 | } 30 | 31 | public function unserialize($str) { 32 | throw new Exception("123456"); 33 | } 34 | } 35 | 36 | function mycb($memc, $key, $value) { 37 | return 0; 38 | } 39 | 40 | $data = new Foo(); 41 | 42 | $m->set('foo', $data, 10); 43 | 44 | error_reporting(0); 45 | try { 46 | var_dump($m->getDelayed(array('foo'), false, 'mycb')); 47 | } catch (Exception $e) { 48 | echo error_get_last()["message"], "\n"; 49 | echo $e->getMessage(), "\n"; 50 | } 51 | 52 | --EXPECTF-- 53 | Memcached::getDelayed(): could not unserialize value%S 54 | 123456 55 | -------------------------------------------------------------------------------- /tests/experimental/getdelayed_bykey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getDelayedByKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'foo-data', 12 | 'bar' => 'bar-data', 13 | 'baz' => 'baz-data', 14 | 'lol' => 'lol-data', 15 | 'kek' => 'kek-data', 16 | ); 17 | 18 | foreach ($data as $k => $v) { 19 | $m->setByKey('kef', $k, $v, 3600); 20 | } 21 | 22 | function myfunc() { 23 | $datas = func_get_args(); 24 | if (isset($datas[1])) { 25 | if (isset($datas[1]['cas']) and $datas[1]['cas'] == 0) { 26 | echo "Invalid cas\n"; 27 | } else { 28 | unset($datas[1]['cas']); 29 | } 30 | var_dump($datas[1]); 31 | } 32 | } 33 | 34 | $m->getDelayedByKey('kef', array_keys($data), false, 'myfunc'); 35 | 36 | ?> 37 | --EXPECT-- 38 | array(2) { 39 | ["key"]=> 40 | string(3) "foo" 41 | ["value"]=> 42 | string(8) "foo-data" 43 | } 44 | array(2) { 45 | ["key"]=> 46 | string(3) "bar" 47 | ["value"]=> 48 | string(8) "bar-data" 49 | } 50 | array(2) { 51 | ["key"]=> 52 | string(3) "baz" 53 | ["value"]=> 54 | string(8) "baz-data" 55 | } 56 | array(2) { 57 | ["key"]=> 58 | string(3) "lol" 59 | ["value"]=> 60 | string(8) "lol-data" 61 | } 62 | array(2) { 63 | ["key"]=> 64 | string(3) "kek" 65 | ["value"]=> 66 | string(8) "kek-data" 67 | } 68 | -------------------------------------------------------------------------------- /tests/experimental/getdelayed_bykey_cas.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getDelayedByKey() with CAS 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'foo-data', 12 | 'bar' => 'bar-data', 13 | 'baz' => 'baz-data', 14 | 'lol' => 'lol-data', 15 | 'kek' => 'kek-data', 16 | ); 17 | 18 | foreach ($data as $k => $v) { 19 | $m->setByKey('kef', $k, $v, 3600); 20 | } 21 | 22 | function myfunc() { 23 | $datas = func_get_args(); 24 | if (isset($datas[1])) { 25 | if (isset($datas[1]['cas']) and $datas[1]['cas'] == 0) { 26 | echo "Invalid cas\n"; 27 | } 28 | var_dump($datas[1]); 29 | } 30 | } 31 | 32 | $m->getDelayedByKey('kef', array_keys($data), true, 'myfunc'); 33 | 34 | ?> 35 | --EXPECTF-- 36 | array(3) { 37 | ["key"]=> 38 | string(3) "foo" 39 | ["value"]=> 40 | string(8) "foo-data" 41 | ["cas"]=> 42 | float(%d) 43 | } 44 | array(3) { 45 | ["key"]=> 46 | string(3) "bar" 47 | ["value"]=> 48 | string(8) "bar-data" 49 | ["cas"]=> 50 | float(%d) 51 | } 52 | array(3) { 53 | ["key"]=> 54 | string(3) "baz" 55 | ["value"]=> 56 | string(8) "baz-data" 57 | ["cas"]=> 58 | float(%d) 59 | } 60 | array(3) { 61 | ["key"]=> 62 | string(3) "lol" 63 | ["value"]=> 64 | string(8) "lol-data" 65 | ["cas"]=> 66 | float(%d) 67 | } 68 | array(3) { 69 | ["key"]=> 70 | string(3) "kek" 71 | ["value"]=> 72 | string(8) "kek-data" 73 | ["cas"]=> 74 | float(%d) 75 | } 76 | -------------------------------------------------------------------------------- /tests/experimental/getdelayed_cbthrows.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getDelayedByKey() with callback exception 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'foo-data', 12 | 'bar' => 'bar-data', 13 | 'baz' => 'baz-data', 14 | 'lol' => 'lol-data', 15 | 'kek' => 'kek-data', 16 | ); 17 | 18 | function myfunc() { 19 | echo "called\n"; 20 | throw new Exception("1234"); 21 | } 22 | 23 | error_reporting(0); 24 | try { 25 | $m->getDelayedByKey('kef', array_keys($data), false, 'myfunc'); 26 | } catch (Exception $e) { 27 | echo error_get_last()["message"], "\n"; 28 | echo $e->getMessage(), "\n"; 29 | } 30 | 31 | --EXPECTF-- 32 | called 33 | Memcached::%s(): could not invoke%s 34 | 1234 35 | -------------------------------------------------------------------------------- /tests/experimental/getdelayed_nonstring_keys.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached getDelayed non string keys 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'foo-data', 18 | 'bar' => 'bar-data', 19 | 3 => '3-data', 20 | ); 21 | 22 | foreach ($data as $k => $v) { 23 | $m->set($k, $v, 3600); 24 | } 25 | 26 | function myfunc() { 27 | $datas = func_get_args(); 28 | if (isset($datas[1])) { 29 | unset($datas[1]['cas']); 30 | var_dump($datas[1]); 31 | } 32 | } 33 | 34 | $keys = array('foo', 35 | $k = new Bar(), 36 | 3, 37 | ); 38 | 39 | $m->getDelayed($keys, false, 'myfunc'); 40 | 41 | if ($keys[0] !== 'foo') { 42 | echo "String 'foo' was coerced to: "; 43 | var_dump($keys[0]); 44 | } 45 | 46 | if (!$keys[1] instanceof Bar) { 47 | echo "Object was coerced to: "; 48 | var_dump($keys[1]); 49 | } 50 | 51 | if ($keys[2] !== 3) { 52 | echo "Integer 3 was coerced to: "; 53 | var_dump($keys[2]); 54 | } 55 | --EXPECT-- 56 | array(2) { 57 | ["key"]=> 58 | string(3) "foo" 59 | ["value"]=> 60 | string(8) "foo-data" 61 | } 62 | array(2) { 63 | ["key"]=> 64 | string(3) "bar" 65 | ["value"]=> 66 | string(8) "bar-data" 67 | } 68 | array(2) { 69 | ["key"]=> 70 | string(1) "3" 71 | ["value"]=> 72 | string(6) "3-data" 73 | } 74 | -------------------------------------------------------------------------------- /tests/experimental/getmulti_badserver.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getMulti() bad server 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getMulti(array('foo', 'bar'))); 9 | echo $m->getResultMessage(), "\n"; 10 | 11 | $m->addServer('localhost', 37712, 1); 12 | 13 | var_dump($m->getMulti(array('foo', 'bar'))); 14 | switch ($m->getResultCode()) { 15 | case Memcached::RES_ERRNO: 16 | case Memcached::RES_SOME_ERRORS: 17 | case Memcached::RES_FAILURE: 18 | break; 19 | default: 20 | echo $m->getResultCode(), ": "; 21 | echo $m->getResultMessage(), "\n"; 22 | } 23 | 24 | --EXPECTF-- 25 | array(0) { 26 | } 27 | NO SERVERS DEFINED 28 | array(0) { 29 | } 30 | %d: %s 31 | -------------------------------------------------------------------------------- /tests/experimental/getmulti_badunserialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getMulti() with bad unserialize 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set('bar', "12", 10)); 29 | var_dump($m->set('foo', new Foo(), 10)); 30 | error_reporting(0); 31 | 32 | try { 33 | var_dump($m->getMulti(array('bar', 'foo'))); 34 | } catch (Exception $e) { 35 | echo error_get_last()["message"], "\n"; 36 | echo $e->getMessage(), "\n"; 37 | } 38 | 39 | --EXPECTF-- 40 | bool(true) 41 | bool(true) 42 | Memcached::%s(): could not unserialize%s 43 | 123456 44 | -------------------------------------------------------------------------------- /tests/experimental/getmulti_bykey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getMultiByKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set('foo', 1, 10); 11 | $m->set('bar', 2, 10); 12 | $m->delete('baz'); 13 | 14 | var_dump($m->getMultiByKey('foo', array('foo', 'bar', 'baz'), Memcached::GET_PRESERVE_ORDER)); 15 | echo $m->getResultMessage(), "\n"; 16 | 17 | var_dump($m->getMultiByKey('foo', array(), Memcached::GET_PRESERVE_ORDER)); 18 | echo $m->getResultMessage(), "\n"; 19 | 20 | --EXPECT-- 21 | array(3) { 22 | ["foo"]=> 23 | int(1) 24 | ["bar"]=> 25 | int(2) 26 | ["baz"]=> 27 | NULL 28 | } 29 | SUCCESS 30 | array(0) { 31 | } 32 | NOT FOUND 33 | -------------------------------------------------------------------------------- /tests/experimental/getmulti_empty.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getMulti() with empty array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getMulti(array()); 11 | var_dump($v); 12 | 13 | --EXPECT-- 14 | array(0) { 15 | } 16 | -------------------------------------------------------------------------------- /tests/experimental/getmulti_partial_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getMulti() partial error 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setMulti($data)); 15 | 16 | /* make sure that all keys are not there */ 17 | var_dump(count($m->deleteMulti(array("key1", "key2"))) == 2); 18 | 19 | $v = $m->getMulti(array_keys($data)); 20 | var_dump(is_array($v)); 21 | var_dump(count($v) < count($data)); 22 | var_dump($m->getResultCode() == Memcached::RES_SUCCESS || 23 | $m->getResultCode() == Memcached::RES_SOME_ERRORS); 24 | 25 | --EXPECT-- 26 | bool(true) 27 | bool(true) 28 | bool(true) 29 | bool(true) 30 | bool(true) 31 | -------------------------------------------------------------------------------- /tests/experimental/getversion.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getVersion() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getVersion()); 9 | 10 | include dirname(dirname(__FILE__)) . "/config.inc"; 11 | $m = memc_get_instance (); 12 | 13 | $stats = $m->getVersion(); 14 | var_dump($stats); 15 | 16 | --EXPECTF-- 17 | bool(false) 18 | array(%d) { 19 | ["%s:%d"]=> 20 | string(%d) "%s" 21 | } 22 | -------------------------------------------------------------------------------- /tests/experimental/locale_float.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Float should not consider locale 3 | --SKIPIF-- 4 | set('test', 13882.1332451)); 18 | $n = $memcache->get('test'); 19 | setlocale(LC_NUMERIC, "C"); 20 | var_dump($n); 21 | 22 | --EXPECT-- 23 | bool(true) 24 | float(13882.1332451) 25 | -------------------------------------------------------------------------------- /tests/experimental/moduleinfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::phpinfo() 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | enabled 22 | %A 23 | -------------------------------------------------------------------------------- /tests/experimental/prepend_bykey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::appendByKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setOption(Memcached::OPT_COMPRESSION, false); 10 | 11 | var_dump($m->setByKey('foo', 'foo', 'bar', 10)); 12 | echo $m->getResultMessage(), "\n"; 13 | var_dump($m->prependByKey('foo', 'foo', 'baz')); 14 | echo $m->getResultMessage(), "\n"; 15 | var_dump($m->getByKey('foo', 'foo')); 16 | 17 | --EXPECT-- 18 | bool(true) 19 | SUCCESS 20 | bool(true) 21 | SUCCESS 22 | string(6) "bazbar" 23 | -------------------------------------------------------------------------------- /tests/experimental/replace_bykey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::replaceByKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete('foo'); 12 | var_dump($m->replaceByKey('kef', 'foo', 'bar', 60)); 13 | echo error_get_last()["message"], "\n"; 14 | echo $m->getResultMessage(), "\n"; 15 | var_dump($m->getByKey('kef', 'foo')); 16 | 17 | $m->setByKey('kef', 'foo', 'kef'); 18 | var_dump($m->replaceByKey('kef', 'foo', 'bar', 60)); 19 | var_dump($m->getByKey('kef', 'foo')); 20 | 21 | --EXPECTF-- 22 | bool(false) 23 | 24 | %rNOT STORED|NOT FOUND%r 25 | bool(false) 26 | bool(true) 27 | string(3) "bar" 28 | -------------------------------------------------------------------------------- /tests/experimental/serializer/serializer_php.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Serializer basic 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | setOption(Memcached::OPT_SERIALIZER, $serializer)); 17 | 18 | $array = range(1, 20000, 1); 19 | 20 | $m->set('foo', $array, 10); 21 | $rv = $m->get('foo'); 22 | var_dump($array === $rv); 23 | 24 | --EXPECT-- 25 | bool(true) 26 | bool(true) 27 | -------------------------------------------------------------------------------- /tests/experimental/serializer/serializer_php_bad_serialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Serializer: exception while serializing 3 | --SKIPIF-- 4 | setOption(Memcached::OPT_SERIALIZER, $serializer)); 41 | 42 | $m->set('foo', 10, 10); 43 | error_reporting(0); 44 | try { 45 | var_dump($m->set('foo', new Foo(), 10)); 46 | } catch (Exception $e) { 47 | echo error_get_last()["message"], "\n"; 48 | echo $e->getMessage(), "\n"; 49 | } 50 | try { 51 | var_dump($m->get('foo')); 52 | } catch (Exception $e) { 53 | // this _should_ never happen, since the get should return 10 54 | // and the previous invalid set shouldn't have worked 55 | echo $e->getMessage(), "\n"; 56 | } 57 | 58 | --EXPECT-- 59 | bool(true) 60 | 61 | 12 62 | int(10) 63 | -------------------------------------------------------------------------------- /tests/experimental/serializer/serializer_php_bad_unserialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Serializer: exception while unserializing 3 | --SKIPIF-- 4 | setOption(Memcached::OPT_SERIALIZER, $serializer)); 37 | 38 | error_reporting(0); 39 | var_dump($m->set('foo', new Foo(), 10)); 40 | try { 41 | var_dump($m->get('foo')); 42 | } catch (Exception $e) { 43 | echo error_get_last()["message"], "\n"; 44 | echo $e->getMessage(), "\n"; 45 | } 46 | 47 | --EXPECTF-- 48 | bool(true) 49 | bool(true) 50 | %scould not unserialize%s 51 | 123456 52 | -------------------------------------------------------------------------------- /tests/experimental/serializer_igbinary.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Serialize igbinary 3 | --SKIPIF-- 4 | 10 | --REDIRECTTEST-- 11 | 12 | $path = implode(DIRECTORY_SEPARATOR, array('tests', 'experimental', 'serializer')); 13 | 14 | return array( 15 | 'TESTS' => $path, 16 | 'ENV' => array('TEST_MEMC_SERIALIZER' => 'Memcached::SERIALIZER_IGBINARY'), 17 | ); 18 | -------------------------------------------------------------------------------- /tests/experimental/serializer_json.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Serialize JSON 3 | --SKIPIF-- 4 | 9 | --REDIRECTTEST-- 10 | 11 | return array( 12 | 'TESTS' => sys_get_temp_dir(), 13 | 'ENV' => array('TEST_MEMC_SERIALIZER' => 'Memcached::SERIALIZER_JSON'), 14 | ); 15 | -------------------------------------------------------------------------------- /tests/experimental/session_gc.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Session expiration 3 | --SKIPIF-- 4 | 11 | --INI-- 12 | memcached.sess_prefix = "memc.sess.key." 13 | session.save_path="127.0.0.1:11211" 14 | session.save_handler = memcached 15 | session.gc_maxlifetime = 2 16 | 17 | --FILE-- 18 | 43 | int(1) 44 | } 45 | NULL 46 | array(1) { 47 | ["foo"]=> 48 | int(1) 49 | } 50 | array(0) { 51 | } 52 | -------------------------------------------------------------------------------- /tests/experimental/set_bykey.phpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/d1b6afd66ad97d4e93220647e9b7ad23ef130154/tests/experimental/set_bykey.phpt -------------------------------------------------------------------------------- /tests/experimental/set_comp_below_factor.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Compress below factor and fail to plain. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set('foo', $array, 10); 15 | $rv = $m->get('foo'); 16 | var_dump($array === $rv); 17 | 18 | 19 | --EXPECT-- 20 | bool(true) 21 | -------------------------------------------------------------------------------- /tests/experimental/set_default_serializer.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Set default serializer 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getOption(Memcached::OPT_SERIALIZER); 10 | $ok = ini_set('memcached.serializer', $serializer); 11 | if ($ok !== false) { 12 | $ok = ini_get('memcached.serializer') == $serializer; 13 | } 14 | 15 | if ($ok) { 16 | $m = new Memcached(); 17 | $s = $m->getOption(Memcached::OPT_SERIALIZER); 18 | if ($s != $m_serializer) { 19 | echo "Serializer is $s, should be $m_serializer ($serializer)\n"; 20 | } 21 | } 22 | 23 | if ($old_m->getOption(Memcached::OPT_SERIALIZER) != $old_s) { 24 | echo "Should not change instantiated objects.\n"; 25 | } 26 | } 27 | 28 | 29 | $m = new Memcached(); 30 | $serializer = ini_get('memcached.serializer'); 31 | $s = $m->getOption(Memcached::OPT_SERIALIZER); 32 | if ($serializer == "igbinary" && $s == Memcached::SERIALIZER_IGBINARY 33 | || $serializer == "php" && $s == Memcached::SERIALIZER_PHP) { 34 | echo "OK: $serializer\n"; 35 | } else { 36 | echo "Differing serializer: $serializer vs. $s\n"; 37 | } 38 | 39 | comp_serializer($m, 'json', Memcached::SERIALIZER_JSON); 40 | comp_serializer($m, 'igbinary', Memcached::SERIALIZER_IGBINARY); 41 | comp_serializer($m, 'json_array', Memcached::SERIALIZER_JSON_ARRAY); 42 | comp_serializer($m, 'php', Memcached::SERIALIZER_PHP); 43 | 44 | --EXPECTF-- 45 | OK: %rigbinary|php%r 46 | -------------------------------------------------------------------------------- /tests/experimental/set_invalid_serializer.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Set invalid serializer 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | set('foo', $array, 10); 14 | $rv = $m->get('foo'); 15 | var_dump($array === $rv); 16 | 17 | 18 | --EXPECT-- 19 | bool(true) 20 | -------------------------------------------------------------------------------- /tests/experimental/setmulti_badserialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::setMultiByKey() with bad serialize 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setByKey('kef', 'foo', 10, 10); 30 | try { 31 | var_dump($m->setMultiByKey('kef', array('foo' => new Foo()), 10)); 32 | } catch (Exception $e) { 33 | if (version_compare(phpversion(), "5.3.0", ">=")) { 34 | if ($e->getPrevious()) { 35 | $e = $e->getPrevious(); 36 | } 37 | } 38 | 39 | echo error_get_last()["message"], "\n"; 40 | echo $e->getMessage(), "\n"; 41 | } 42 | var_dump($m->getByKey('kef', 'foo')); 43 | 44 | --EXPECT-- 45 | 1234 46 | int(10) 47 | -------------------------------------------------------------------------------- /tests/experimental/setmulti_bykey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::setMultiByKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | $item) { 10 | if ($data[$key] !== $item) { 11 | echo "Expected:\n"; 12 | var_dump($data[$key]); 13 | echo "Actual:\n"; 14 | var_dump($item); 15 | echo "Key:\n"; 16 | var_dump($key); 17 | } 18 | 19 | unset($data[$key]); 20 | } 21 | 22 | // keys must be strings. 23 | unset($data[100]); 24 | if ($data) { 25 | echo "Missing keys:\n"; 26 | var_dump($data); 27 | } 28 | } 29 | 30 | 31 | include dirname(dirname(__FILE__)) . '/config.inc'; 32 | $m = memc_get_instance (); 33 | 34 | $data = array( 35 | 'foo' => 'foo-data', 36 | 'bar' => 'bar-data', 37 | 'baz' => 'baz-data', 38 | 'lol' => 'lol-data', 39 | 'kek' => 'kek-data', 40 | ); 41 | $data[100] = 'int-data'; 42 | 43 | var_dump($m->setMultiByKey('kef', $data, 10)); 44 | $r = $m->getMultiByKey('kef', array_keys($data)); 45 | 46 | simple_compare($data, $r, false); 47 | 48 | --EXPECT-- 49 | bool(true) 50 | -------------------------------------------------------------------------------- /tests/experimental/stats.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getStats() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getStats()); 9 | 10 | $m->addServer('localhost', 11211, 1); 11 | 12 | $stats = $m->getStats(); 13 | var_dump($stats); 14 | 15 | --EXPECTF-- 16 | array(0) { 17 | } 18 | array(%d) { 19 | ["%s:%d"]=> 20 | array(%d) { 21 | ["pid"]=> 22 | int(%d) 23 | ["uptime"]=> 24 | int(%d) 25 | ["threads"]=> 26 | int(%d) 27 | ["time"]=> 28 | int(%d) 29 | ["pointer_size"]=> 30 | int(%d) 31 | ["rusage_user_seconds"]=> 32 | int(%d) 33 | ["rusage_user_microseconds"]=> 34 | int(%d) 35 | ["rusage_system_seconds"]=> 36 | int(%d) 37 | ["rusage_system_microseconds"]=> 38 | int(%d) 39 | ["curr_items"]=> 40 | int(%d) 41 | ["total_items"]=> 42 | int(%d) 43 | ["limit_maxbytes"]=> 44 | int(%d) 45 | ["curr_connections"]=> 46 | int(%d) 47 | ["total_connections"]=> 48 | int(%d) 49 | ["connection_structures"]=> 50 | int(%d) 51 | ["bytes"]=> 52 | int(%d) 53 | ["cmd_get"]=> 54 | int(%d) 55 | ["cmd_set"]=> 56 | int(%d) 57 | ["get_hits"]=> 58 | int(%d) 59 | ["get_misses"]=> 60 | int(%d) 61 | ["evictions"]=> 62 | int(%d) 63 | ["bytes_read"]=> 64 | int(%d) 65 | ["bytes_written"]=> 66 | int(%d) 67 | ["version"]=> 68 | string(%d) "%s" 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/experimental/stats_badserver.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getStats() with bad server 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getResultMessage(), "\n"; 10 | var_dump($m->getStats()); 11 | 12 | $m->addServer('localhost', 43971, 1); 13 | $m->addServer('localhost', 11211, 1); 14 | 15 | $stats = $m->getStats(); 16 | 17 | // should be a partial result 18 | echo $m->getResultMessage(), "\n"; 19 | 20 | // there should be stats only for one server 21 | var_dump(count($stats)); 22 | 23 | var_dump($stats['localhost:11211']['pid'] > 0); 24 | var_dump(count($stats['localhost:11211'])); 25 | 26 | --EXPECTF-- 27 | SUCCESS 28 | array(0) { 29 | } 30 | SOME ERRORS WERE REPORTED 31 | int(2) 32 | bool(true) 33 | int(%d) 34 | -------------------------------------------------------------------------------- /tests/expire.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached store, fetch & touch expired key 3 | --SKIPIF-- 4 | 10 | --FILE-- 11 | set($key, "foo", 2); 20 | $v = $m->get($key); 21 | if (!$set || $v != 'foo') { 22 | echo "Error setting key to \"foo\" with 2s expiry.\n"; 23 | return; 24 | } 25 | 26 | sleep(1); 27 | $res = $m->touch($key, 2); 28 | $v = $m->get($key); 29 | 30 | if(!$res || $v != 'foo') { 31 | echo "Error touching key for another 2s expiry.\n"; 32 | var_dump($res); 33 | var_dump($m->getResultMessage()); 34 | var_dump($v); 35 | return; 36 | } 37 | 38 | sleep(3); 39 | $v = $m->get($key); 40 | 41 | if ($v !== Memcached::GET_ERROR_RETURN_VALUE) { 42 | echo "Wanted:\n"; 43 | var_dump(Memcached::GET_ERROR_RETURN_VALUE); 44 | echo "from get of expired value. Got:\n"; 45 | var_dump($v); 46 | return; 47 | } 48 | echo "All OK" . PHP_EOL; 49 | } 50 | 51 | $m = memc_get_instance (array ( 52 | Memcached::OPT_BINARY_PROTOCOL => true 53 | )); 54 | 55 | echo '-- binary protocol' . PHP_EOL; 56 | run_expiry_test ($m); 57 | 58 | $m = memc_get_instance (); 59 | 60 | echo '-- text protocol' . PHP_EOL; 61 | run_expiry_test ($m); 62 | 63 | echo "DONE TEST\n"; 64 | ?> 65 | --EXPECT-- 66 | -- binary protocol 67 | All OK 68 | -- text protocol 69 | All OK 70 | DONE TEST 71 | -------------------------------------------------------------------------------- /tests/flush_buffers.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test flushing buffers 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 11 | Memcached::OPT_BUFFER_WRITES => 1, 12 | )); 13 | 14 | $key = uniqid ('flush_key_'); 15 | 16 | var_dump ($m->set($key, 'test_val')); 17 | 18 | $m2 = memc_get_instance (); 19 | 20 | var_dump ($m2->get ($key)); 21 | var_dump ($m->flushBuffers ()); 22 | sleep (1); 23 | var_dump ($m2->get ($key)); 24 | 25 | echo "OK" . PHP_EOL; 26 | ?> 27 | --EXPECT-- 28 | bool(true) 29 | bool(false) 30 | bool(true) 31 | string(8) "test_val" 32 | OK -------------------------------------------------------------------------------- /tests/get_flags.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::get/getMulti() flags 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set ($key1, 'hello1', 20); 14 | $m->set ($key2, 'hello2', 20); 15 | 16 | $value = $m->get($key1); 17 | $extended = $m->get($key1, null, Memcached::GET_EXTENDED); 18 | 19 | var_dump ($value); 20 | var_dump ($extended); 21 | 22 | $values = $m->getMulti(array ($key1, $key2), Memcached::GET_PRESERVE_ORDER); 23 | $extended = $m->getMulti(array ($key1, $key2), Memcached::GET_EXTENDED | Memcached::GET_PRESERVE_ORDER); 24 | 25 | var_dump ($values); 26 | var_dump ($extended); 27 | echo "OK"; 28 | 29 | --EXPECTF-- 30 | string(6) "hello1" 31 | array(3) { 32 | ["value"]=> 33 | string(6) "hello1" 34 | ["cas"]=> 35 | int(%d) 36 | ["flags"]=> 37 | int(0) 38 | } 39 | array(2) { 40 | ["memc.test.%s"]=> 41 | string(6) "hello1" 42 | ["memc.test.%s"]=> 43 | string(6) "hello2" 44 | } 45 | array(2) { 46 | ["memc.test.%s"]=> 47 | array(3) { 48 | ["value"]=> 49 | string(6) "hello1" 50 | ["cas"]=> 51 | int(%d) 52 | ["flags"]=> 53 | int(0) 54 | } 55 | ["memc.test.%s"]=> 56 | array(3) { 57 | ["value"]=> 58 | string(6) "hello2" 59 | ["cas"]=> 60 | int(%d) 61 | ["flags"]=> 62 | int(0) 63 | } 64 | } 65 | OK -------------------------------------------------------------------------------- /tests/getdelayed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached getDelayed callback 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'foo-data', 12 | 'bar' => 'bar-data', 13 | 'baz' => 'baz-data', 14 | 'lol' => 'lol-data', 15 | 'kek' => 'kek-data', 16 | ); 17 | 18 | foreach ($data as $k => $v) { 19 | $m->set($k, $v, 3600); 20 | } 21 | 22 | function myfunc() { 23 | $datas = func_get_args(); 24 | if (isset($datas[1])) { 25 | var_dump($datas[1]); 26 | } 27 | } 28 | 29 | $m->getDelayed(array_keys($data), true, 'myfunc'); 30 | 31 | ?> 32 | --EXPECTF-- 33 | array(4) { 34 | ["key"]=> 35 | string(3) "foo" 36 | ["value"]=> 37 | string(8) "foo-data" 38 | ["cas"]=> 39 | int(%d) 40 | ["flags"]=> 41 | int(0) 42 | } 43 | array(4) { 44 | ["key"]=> 45 | string(3) "bar" 46 | ["value"]=> 47 | string(8) "bar-data" 48 | ["cas"]=> 49 | int(%d) 50 | ["flags"]=> 51 | int(0) 52 | } 53 | array(4) { 54 | ["key"]=> 55 | string(3) "baz" 56 | ["value"]=> 57 | string(8) "baz-data" 58 | ["cas"]=> 59 | int(%d) 60 | ["flags"]=> 61 | int(0) 62 | } 63 | array(4) { 64 | ["key"]=> 65 | string(3) "lol" 66 | ["value"]=> 67 | string(8) "lol-data" 68 | ["cas"]=> 69 | int(%d) 70 | ["flags"]=> 71 | int(0) 72 | } 73 | array(4) { 74 | ["key"]=> 75 | string(3) "kek" 76 | ["value"]=> 77 | string(8) "kek-data" 78 | ["cas"]=> 79 | int(%d) 80 | ["flags"]=> 81 | int(0) 82 | } -------------------------------------------------------------------------------- /tests/getmulti.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getMulti() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setMulti($data)); 22 | 23 | $keys = array_keys($data); 24 | $keys['last'] = new Foo(); 25 | 26 | $v = $m->getMulti($keys); 27 | var_dump(is_array($v)); 28 | var_dump($m->getResultCode() == Memcached::RES_SUCCESS); 29 | if (is_array($v)) { 30 | foreach ($v as $key => $value) { 31 | if (!isset($data[$key]) or $value !== $data[$key]) { 32 | echo "mismatch \$data['$key'] = \n"; 33 | var_dump($data[$key]); 34 | var_dump($value); 35 | } 36 | } 37 | } else { 38 | echo "Result not an array\n"; 39 | } 40 | 41 | var_dump(is_object($keys['last'])); 42 | 43 | --EXPECT-- 44 | bool(true) 45 | bool(true) 46 | bool(true) 47 | bool(true) 48 | -------------------------------------------------------------------------------- /tests/getserverbykey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::getServerByKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getServerByKey("a")); 11 | 12 | $m->addServer('localhost', 11211, 1); 13 | $m->addServer('localhost', 11212, 1); 14 | $m->addServer('localhost', 11213, 1); 15 | $m->addServer('localhost', 11214, 1); 16 | $m->addServer('localhost', 11215, 1); 17 | 18 | var_dump($m->getServerByKey("")); 19 | echo $m->getResultMessage(), "\n"; 20 | var_dump($m->getServerByKey("a")); 21 | var_dump($m->getServerByKey("b")); 22 | var_dump($m->getServerByKey("c")); 23 | var_dump($m->getServerByKey("d")); 24 | --EXPECTF-- 25 | bool(false) 26 | bool(false) 27 | A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE 28 | array(%d) { 29 | ["host"]=> 30 | string(%d) "%s" 31 | ["port"]=> 32 | int(%d) 33 | ["weight"]=> 34 | int(0) 35 | } 36 | array(%d) { 37 | ["host"]=> 38 | string(%d) "%s" 39 | ["port"]=> 40 | int(%d) 41 | ["weight"]=> 42 | int(0) 43 | } 44 | array(%d) { 45 | ["host"]=> 46 | string(%d) "%s" 47 | ["port"]=> 48 | int(%d) 49 | ["weight"]=> 50 | int(0) 51 | } 52 | array(%d) { 53 | ["host"]=> 54 | string(%d) "%s" 55 | ["port"]=> 56 | int(%d) 57 | ["weight"]=> 58 | int(0) 59 | } 60 | -------------------------------------------------------------------------------- /tests/getserverlist.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | getServerList 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array ( 'KEYHERE' => 'localhost', 11211, 3 ), ); 8 | $m = new memcached(); 9 | var_dump($m->getServerList()); 10 | $m->addServers($servers); 11 | var_dump($m->getServerList()); 12 | $m->addServers($servers); 13 | var_dump($m->getServerList()); 14 | $m = new memcached(); 15 | $m->addServer('127.0.0.1', 11211); 16 | var_dump($m->getServerList()); 17 | 18 | echo "OK"; 19 | ?> 20 | --EXPECT-- 21 | array(0) { 22 | } 23 | array(1) { 24 | [0]=> 25 | array(3) { 26 | ["host"]=> 27 | string(9) "localhost" 28 | ["port"]=> 29 | int(11211) 30 | ["type"]=> 31 | string(3) "TCP" 32 | } 33 | } 34 | array(2) { 35 | [0]=> 36 | array(3) { 37 | ["host"]=> 38 | string(9) "localhost" 39 | ["port"]=> 40 | int(11211) 41 | ["type"]=> 42 | string(3) "TCP" 43 | } 44 | [1]=> 45 | array(3) { 46 | ["host"]=> 47 | string(9) "localhost" 48 | ["port"]=> 49 | int(11211) 50 | ["type"]=> 51 | string(3) "TCP" 52 | } 53 | } 54 | array(1) { 55 | [0]=> 56 | array(3) { 57 | ["host"]=> 58 | string(9) "127.0.0.1" 59 | ["port"]=> 60 | int(11211) 61 | ["type"]=> 62 | string(3) "TCP" 63 | } 64 | } 65 | OK -------------------------------------------------------------------------------- /tests/gh_155.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for bug 155 3 | --SKIPIF-- 4 | 12 | --FILE-- 13 | setOption(Memcached::OPT_BINARY_PROTOCOL, true); 19 | $m->addServer(MEMC_SERVER_HOST, MEMC_SERVER_PORT); 20 | 21 | $key = 'bug_155_' . uniqid(); 22 | 23 | $m->set ($key, 'test', time() + 86400); 24 | 25 | $m->get ($key); 26 | echo "GET: " . $m->getResultMessage() . PHP_EOL; 27 | 28 | $m->touch ($key, time() + 86400); 29 | echo "TOUCH: " . $m->getResultMessage() . PHP_EOL; 30 | 31 | $m->touch ($key, time() + 86400); 32 | echo "TOUCH: " . $m->getResultMessage() . PHP_EOL; 33 | 34 | $m->get ($key); 35 | echo "GET: " . $m->getResultMessage() . PHP_EOL; 36 | 37 | $m->get ($key); 38 | echo "GET: " . $m->getResultMessage() . PHP_EOL; 39 | 40 | echo "DONE" . PHP_EOL; 41 | 42 | --EXPECT-- 43 | GET: SUCCESS 44 | TOUCH: SUCCESS 45 | TOUCH: SUCCESS 46 | GET: SUCCESS 47 | GET: SUCCESS 48 | DONE 49 | -------------------------------------------------------------------------------- /tests/gh_21.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for Github issue 21 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setOption(Memcached::OPT_BINARY_PROTOCOL, true); 14 | 15 | $m->addServers($newServers); 16 | 17 | $d = $m->get('foo'); 18 | 19 | $m->set('counter', 5); 20 | $n = $m->decrement('counter'); 21 | var_dump($n); 22 | 23 | $n = $m->decrement('counter', 10); 24 | var_dump($n); 25 | 26 | var_dump($m->get('counter')); 27 | 28 | $m->set('counter', 'abc'); 29 | $n = $m->increment('counter'); 30 | var_dump($n); 31 | ?> 32 | --EXPECT-- 33 | int(4) 34 | int(0) 35 | int(0) 36 | bool(false) -------------------------------------------------------------------------------- /tests/gh_500.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for Github issue 500 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addServers($newServers); 14 | 15 | $m->set('floatpoint', 100.2); 16 | $n = $m->get('floatpoint'); 17 | var_dump($n); 18 | 19 | $m->set('floatpoint_neg', -300.4); 20 | $n = $m->get('floatpoint_neg'); 21 | var_dump($n); 22 | ?> 23 | --EXPECT-- 24 | float(100.2) 25 | float(-300.4) 26 | -------------------------------------------------------------------------------- /tests/gh_77.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for Github issue #77 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | touch($key, 5); 17 | var_dump ($mc->getResultCode() == Memcached::RES_NOTFOUND); 18 | $mc->set($key, 1, 5); 19 | 20 | $mc->set($key, 1, 5); 21 | var_dump ($mc->getResultCode() == Memcached::RES_SUCCESS); 22 | 23 | echo "OK\n"; 24 | 25 | ?> 26 | --EXPECT-- 27 | bool(true) 28 | bool(true) 29 | OK 30 | 31 | -------------------------------------------------------------------------------- /tests/gh_90.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for GH #90 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | true 10 | )); 11 | 12 | // Create a key for use as a lock. If this key already exists, wait till it doesn't exist. 13 | { 14 | $key = 'LockKey'; 15 | $lockToken = mt_rand(0, mt_getrandmax()); //Random value for ownership verification 16 | 17 | while (true) 18 | { 19 | $casToken = null; 20 | $data = $memcached->get($key, $casToken); 21 | if ($memcached->getResultCode() == Memcached::RES_NOTFOUND) 22 | { 23 | if ($memcached->add($key, $lockToken, 5)) 24 | { 25 | break; 26 | } 27 | } 28 | elseif ($data === false) 29 | { 30 | if ($memcached->cas($casToken, $key, $lockToken, 5)) 31 | { 32 | break; 33 | } 34 | } 35 | 36 | //Sleep 10 milliseconds 37 | usleep(10 * 1000); 38 | } 39 | } 40 | 41 | //Do something here that requires exclusive access to this key 42 | 43 | //Effectively delete our key lock. 44 | { 45 | $casToken = null; 46 | if ($lockToken == $memcached->get($key, $casToken)) 47 | { 48 | $memcached->cas($casToken, $key, false, 1); 49 | } 50 | } 51 | 52 | //Create 10 keys and then increment them. The first value returned will be wrong. 53 | { 54 | $keyList = array(); 55 | for ($i = 0; $i < 10; $i++) 56 | { 57 | $keyList[] = $i . '_' . uniqid ('count_value_'); 58 | } 59 | 60 | $valueList = array(); 61 | foreach ($keyList as $key) 62 | { 63 | $valueList[$key] = $memcached->increment($key, 1, 1); 64 | } 65 | 66 | var_dump ($valueList); 67 | } 68 | 69 | --EXPECTF-- 70 | array(10) { 71 | ["0_%s"]=> 72 | int(1) 73 | ["1_%s"]=> 74 | int(1) 75 | ["2_%s"]=> 76 | int(1) 77 | ["3_%s"]=> 78 | int(1) 79 | ["4_%s"]=> 80 | int(1) 81 | ["5_%s"]=> 82 | int(1) 83 | ["6_%s"]=> 84 | int(1) 85 | ["7_%s"]=> 86 | int(1) 87 | ["8_%s"]=> 88 | int(1) 89 | ["9_%s"]=> 90 | int(1) 91 | } 92 | -------------------------------------------------------------------------------- /tests/gh_93.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for Github issue #93 (double and long overflow) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | false 10 | )); 11 | 12 | function testOverflow($m, $value) { 13 | $m->delete('overflow'); 14 | if (true !== $m->set('overflow', $value)) { 15 | echo "Error storing 'overflow' variable\n"; 16 | return false; 17 | } 18 | 19 | if (true !== $m->prepend('overflow', str_repeat('0', 128))) { 20 | echo "Error prepending key\n"; 21 | return false; 22 | } 23 | 24 | $v = @$m->get('overflow'); 25 | if ($v !== $value) { 26 | // At least it doesn't segfault, so we're happy for now 27 | // echo "Error receiving 'overflow' variable\n"; 28 | // return false; 29 | return true; 30 | } 31 | 32 | return true; 33 | } 34 | 35 | if (!testOverflow($m, 10)) { 36 | return; 37 | } 38 | 39 | if (!testOverflow($m, 9.09)) { 40 | return; 41 | } 42 | 43 | echo "OK\n"; 44 | ?> 45 | --EXPECT-- 46 | OK -------------------------------------------------------------------------------- /tests/incrdecr.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::increment() Memcached::decrement() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete('foo'); 12 | var_dump($m->increment('foo', 1)); 13 | var_dump($m->getResultCode()); 14 | var_dump($m->decrement('foo', 1)); 15 | var_dump($m->getResultCode()); 16 | var_dump($m->get('foo')); 17 | var_dump($m->getResultCode()); 18 | 19 | echo "Normal\n"; 20 | $m->set('foo', 1); 21 | var_dump($m->get('foo')); 22 | $m->increment('foo'); 23 | var_dump($m->get('foo')); 24 | $m->increment('foo', 2); 25 | var_dump($m->get('foo')); 26 | $m->decrement('foo'); 27 | var_dump($m->get('foo')); 28 | $m->decrement('foo', 2); 29 | var_dump($m->get('foo')); 30 | 31 | error_reporting(0); 32 | 33 | echo "Negative offset\n"; 34 | error_clear_last(); 35 | $m->increment('foo', -1); 36 | echo error_get_last()["message"], "\n"; 37 | var_dump($m->get('foo')); 38 | 39 | error_clear_last(); 40 | $m->decrement('foo', -1); 41 | echo error_get_last()["message"], "\n"; 42 | var_dump($m->get('foo')); 43 | 44 | echo "Enormous offset\n"; 45 | $m->increment('foo', 0x7f000000); 46 | var_dump($m->get('foo')); 47 | 48 | $m->decrement('foo', 0x7f000000); 49 | var_dump($m->get('foo')); 50 | 51 | --EXPECT-- 52 | Not there 53 | bool(false) 54 | int(16) 55 | bool(false) 56 | int(16) 57 | bool(false) 58 | int(16) 59 | Normal 60 | int(1) 61 | int(2) 62 | int(4) 63 | int(3) 64 | int(1) 65 | Negative offset 66 | Memcached::increment(): offset cannot be a negative value 67 | int(1) 68 | Memcached::decrement(): offset cannot be a negative value 69 | int(1) 70 | Enormous offset 71 | int(2130706433) 72 | int(1) 73 | -------------------------------------------------------------------------------- /tests/incrdecr_64.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | 64-bit Memcached::increment() decrement() incrementByKey() decrementByKey() 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | set('foo', 1); 15 | var_dump($m->get('foo')); 16 | 17 | echo "Enormous offset 64-bit\n"; 18 | $m->increment('foo', 0x100000000); 19 | var_dump($m->get('foo')); 20 | 21 | $m->decrement('foo', 0x100000000); 22 | var_dump($m->get('foo')); 23 | 24 | echo "Enormous offset 64-bit by key\n"; 25 | $m->incrementByKey('foo', 'foo', 0x100000000); 26 | var_dump($m->get('foo')); 27 | 28 | $m->decrementByKey('foo', 'foo', 0x100000000); 29 | var_dump($m->get('foo')); 30 | 31 | --EXPECT-- 32 | Normal 33 | int(1) 34 | Enormous offset 64-bit 35 | int(4294967297) 36 | int(1) 37 | Enormous offset 64-bit by key 38 | int(4294967297) 39 | int(1) 40 | -------------------------------------------------------------------------------- /tests/incrdecr_bykey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::incrementByKey() Memcached::decrementByKey() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete('foo'); 12 | var_dump($m->incrementByKey('foo', 'foo', 1)); 13 | var_dump($m->decrementByKey('foo', 'foo', 1)); 14 | var_dump($m->get('foo')); 15 | 16 | echo "Normal\n"; 17 | $m->set('foo', 1); 18 | var_dump($m->get('foo')); 19 | $m->incrementByKey('foo', 'foo'); 20 | var_dump($m->get('foo')); 21 | $m->incrementByKey('foo', 'foo', 2); 22 | var_dump($m->get('foo')); 23 | $m->decrementByKey('foo', 'foo'); 24 | var_dump($m->get('foo')); 25 | $m->decrementByKey('foo', 'foo', 2); 26 | var_dump($m->get('foo')); 27 | 28 | error_reporting(0); 29 | 30 | echo "Negative offset\n"; 31 | error_clear_last(); 32 | $m->incrementByKey('foo', 'foo', -1); 33 | echo error_get_last()["message"], "\n"; 34 | var_dump($m->get('foo')); 35 | 36 | error_clear_last(); 37 | $m->decrementByKey('foo', 'foo', -1); 38 | echo error_get_last()["message"], "\n"; 39 | var_dump($m->get('foo')); 40 | 41 | echo "Enormous offset\n"; 42 | $m->incrementByKey('foo', 'foo', 0x7f000000); 43 | var_dump($m->get('foo')); 44 | 45 | $m->decrementByKey('foo', 'foo', 0x7f000000); 46 | var_dump($m->get('foo')); 47 | 48 | --EXPECT-- 49 | Not there 50 | bool(false) 51 | bool(false) 52 | bool(false) 53 | Normal 54 | int(1) 55 | int(2) 56 | int(4) 57 | int(3) 58 | int(1) 59 | Negative offset 60 | Memcached::incrementByKey(): offset cannot be a negative value 61 | int(1) 62 | Memcached::decrementByKey(): offset cannot be a negative value 63 | int(1) 64 | Enormous offset 65 | int(2130706433) 66 | int(1) 67 | -------------------------------------------------------------------------------- /tests/incrdecr_initial.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::increment() Memcached::decrement() with initial support 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | true 10 | )); 11 | 12 | $m->delete('foo'); 13 | var_dump($m->increment('foo', 1, 1)); 14 | var_dump($m->increment('foo', 0)); 15 | $m->delete('foo'); 16 | 17 | var_dump($m->increment('foo', 1, 1)); 18 | var_dump($m->increment('foo', 1, 1)); 19 | var_dump($m->increment('foo', 1, 1)); 20 | 21 | var_dump($m->decrement('foo', 1, 1)); 22 | var_dump($m->decrement('foo', 0)); 23 | $m->delete('foo'); 24 | 25 | $m->deleteByKey('foo', 'foo'); 26 | var_dump($m->incrementByKey('foo', 'foo', 1, 1)); 27 | var_dump($m->incrementByKey('foo', 'foo', 0)); 28 | $m->deleteByKey('foo', 'foo'); 29 | 30 | var_dump($m->incrementByKey('foo', 'foo', 1, 1)); 31 | var_dump($m->incrementByKey('foo', 'foo', 1, 1)); 32 | var_dump($m->incrementByKey('foo', 'foo', 1, 1)); 33 | 34 | var_dump($m->decrementByKey('foo', 'foo', 1, 1)); 35 | var_dump($m->decrementByKey('foo', 'foo', 0)); 36 | $m->deleteByKey('foo', 'foo'); 37 | 38 | --EXPECT-- 39 | int(1) 40 | int(1) 41 | int(1) 42 | int(2) 43 | int(3) 44 | int(2) 45 | int(2) 46 | int(1) 47 | int(1) 48 | int(1) 49 | int(2) 50 | int(3) 51 | int(2) 52 | int(2) 53 | -------------------------------------------------------------------------------- /tests/incrdecr_invalid_key.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::increment() Memcached::decrement() with invalid key 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | increment('', 1)); 11 | var_dump($m->decrement('', 1)); 12 | ?> 13 | --EXPECT-- 14 | bool(false) 15 | bool(false) 16 | -------------------------------------------------------------------------------- /tests/invalid_options.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Get version 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setOption(500, 23423); 11 | var_dump ($m->getResultCode ()); 12 | 13 | echo "OK" . PHP_EOL; 14 | ?> 15 | --EXPECTF-- 16 | Warning: Memcached::setOption(): error setting memcached option: INVALID ARGUMENTS in %s on line %d 17 | int(38) 18 | OK -------------------------------------------------------------------------------- /tests/invoke_callback.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test that callback is invoked on new object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addServer(MEMC_SERVER_HOST, MEMC_SERVER_PORT); 13 | } 14 | 15 | $m = new Memcached('hi', 'my_func'); 16 | $m = new Memcached('hi', 'my_func'); 17 | 18 | var_dump($m->getServerList()); 19 | 20 | echo "OK\n"; 21 | 22 | --EXPECTF-- 23 | array(1) { 24 | [0]=> 25 | array(3) { 26 | ["host"]=> 27 | string(9) "%s" 28 | ["port"]=> 29 | int(%d) 30 | ["type"]=> 31 | string(3) "TCP" 32 | } 33 | } 34 | OK 35 | -------------------------------------------------------------------------------- /tests/invoke_callback_2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Use callback initializer 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | isPersistent()); 14 | var_dump($id); 15 | } 16 | 17 | function init_cb_fail($m, $id) { 18 | echo "configured, should not be called.\n"; 19 | } 20 | 21 | function init_cb_arg($m, $id) { 22 | var_dump(func_num_args()); 23 | var_dump($id); 24 | } 25 | 26 | function init_nopersist_cb($m, $id) { 27 | var_dump($m->isPersistent()); 28 | var_dump($id); 29 | } 30 | 31 | class Foo extends Memcached { 32 | function __construct($id = null) { 33 | parent::__construct($id, array($this, 'init')); 34 | } 35 | 36 | function init($obj, $id) { 37 | var_dump(func_num_args()); 38 | var_dump($this->isPristine()); 39 | var_dump($this->isPersistent()); 40 | var_dump($id); 41 | } 42 | } 43 | 44 | echo "cb call\n"; 45 | $m1 = new Memcached('foo1', 'init_cb'); 46 | 47 | echo "cb not run\n"; 48 | $m1 = new Memcached('foo1', 'init_cb_fail'); 49 | 50 | echo "cb arg without arg\n"; 51 | $m1 = new Memcached('foo3', 'init_cb_arg'); 52 | 53 | echo "cb arg not persistent\n"; 54 | $m1 = new Memcached(null, 'init_nopersist_cb'); 55 | 56 | echo "cb in object\n"; 57 | $m1 = new Foo(); 58 | 59 | echo "cb persistent in object\n"; 60 | $m1 = new Foo('baz'); 61 | 62 | echo "cb second persistent in object\n"; 63 | $m1 = new Foo('baz'); 64 | ?> 65 | --EXPECT-- 66 | cb call 67 | string(9) "Memcached" 68 | bool(true) 69 | string(4) "foo1" 70 | cb not run 71 | cb arg without arg 72 | int(2) 73 | string(4) "foo3" 74 | cb arg not persistent 75 | bool(false) 76 | NULL 77 | cb in object 78 | int(2) 79 | bool(true) 80 | bool(false) 81 | NULL 82 | cb persistent in object 83 | int(2) 84 | bool(true) 85 | bool(true) 86 | string(3) "baz" 87 | cb second persistent in object 88 | -------------------------------------------------------------------------------- /tests/invoke_callback_twice.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test that callback is invoked on new object only once 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | false, 11 | Memcached::OPT_VERIFY_KEY => false 12 | )); 13 | // libmemcached can verify keys, but these are tests are for our own 14 | // function s_memc_valid_key_ascii, so explicitly disable the checks 15 | // that libmemcached can perform. 16 | 17 | echo 'ASCII: SPACES' . PHP_EOL; 18 | var_dump ($ascii->set ('ascii key with spaces', 'this is a test')); 19 | var_dump ($ascii->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 20 | 21 | echo 'ASCII: NEWLINE' . PHP_EOL; 22 | var_dump ($ascii->set ('asciikeywithnewline' . PHP_EOL, 'this is a test')); 23 | var_dump ($ascii->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 24 | 25 | echo 'ASCII: EMPTY' . PHP_EOL; 26 | var_dump ($ascii->set (''/*empty key*/, 'this is a test')); 27 | var_dump ($ascii->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 28 | 29 | echo 'ASCII: TOO LONG' . PHP_EOL; 30 | var_dump ($ascii->set (str_repeat ('1234567890', 512), 'this is a test')); 31 | var_dump ($ascii->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 32 | 33 | echo 'ASCII: GET' . PHP_EOL; 34 | for ($i=0;$i<32;$i++) { 35 | var_dump ($ascii->get ('asciikeywithnonprintablechar-' . chr($i) . '-here')); 36 | var_dump ($ascii->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 37 | } 38 | 39 | echo 'ASCII: SET' . PHP_EOL; 40 | for ($i=0;$i<32;$i++) { 41 | var_dump ($ascii->set ('asciikeywithnonprintablechar-' . chr($i) . '-here', 'this is a test')); 42 | var_dump ($ascii->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 43 | } 44 | 45 | echo 'OK' . PHP_EOL; 46 | 47 | --EXPECT-- 48 | ASCII: SPACES 49 | bool(false) 50 | bool(true) 51 | ASCII: NEWLINE 52 | bool(false) 53 | bool(true) 54 | ASCII: EMPTY 55 | bool(false) 56 | bool(true) 57 | ASCII: TOO LONG 58 | bool(false) 59 | bool(true) 60 | ASCII: GET 61 | bool(false) 62 | bool(true) 63 | bool(false) 64 | bool(true) 65 | bool(false) 66 | bool(true) 67 | bool(false) 68 | bool(true) 69 | bool(false) 70 | bool(true) 71 | bool(false) 72 | bool(true) 73 | bool(false) 74 | bool(true) 75 | bool(false) 76 | bool(true) 77 | bool(false) 78 | bool(true) 79 | bool(false) 80 | bool(true) 81 | bool(false) 82 | bool(true) 83 | bool(false) 84 | bool(true) 85 | bool(false) 86 | bool(true) 87 | bool(false) 88 | bool(true) 89 | bool(false) 90 | bool(true) 91 | bool(false) 92 | bool(true) 93 | bool(false) 94 | bool(true) 95 | bool(false) 96 | bool(true) 97 | bool(false) 98 | bool(true) 99 | bool(false) 100 | bool(true) 101 | bool(false) 102 | bool(true) 103 | bool(false) 104 | bool(true) 105 | bool(false) 106 | bool(true) 107 | bool(false) 108 | bool(true) 109 | bool(false) 110 | bool(true) 111 | bool(false) 112 | bool(true) 113 | bool(false) 114 | bool(true) 115 | bool(false) 116 | bool(true) 117 | bool(false) 118 | bool(true) 119 | bool(false) 120 | bool(true) 121 | bool(false) 122 | bool(true) 123 | bool(false) 124 | bool(true) 125 | ASCII: SET 126 | bool(false) 127 | bool(true) 128 | bool(false) 129 | bool(true) 130 | bool(false) 131 | bool(true) 132 | bool(false) 133 | bool(true) 134 | bool(false) 135 | bool(true) 136 | bool(false) 137 | bool(true) 138 | bool(false) 139 | bool(true) 140 | bool(false) 141 | bool(true) 142 | bool(false) 143 | bool(true) 144 | bool(false) 145 | bool(true) 146 | bool(false) 147 | bool(true) 148 | bool(false) 149 | bool(true) 150 | bool(false) 151 | bool(true) 152 | bool(false) 153 | bool(true) 154 | bool(false) 155 | bool(true) 156 | bool(false) 157 | bool(true) 158 | bool(false) 159 | bool(true) 160 | bool(false) 161 | bool(true) 162 | bool(false) 163 | bool(true) 164 | bool(false) 165 | bool(true) 166 | bool(false) 167 | bool(true) 168 | bool(false) 169 | bool(true) 170 | bool(false) 171 | bool(true) 172 | bool(false) 173 | bool(true) 174 | bool(false) 175 | bool(true) 176 | bool(false) 177 | bool(true) 178 | bool(false) 179 | bool(true) 180 | bool(false) 181 | bool(true) 182 | bool(false) 183 | bool(true) 184 | bool(false) 185 | bool(true) 186 | bool(false) 187 | bool(true) 188 | bool(false) 189 | bool(true) 190 | OK 191 | -------------------------------------------------------------------------------- /tests/keys_binary.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test valid and invalid keys - binary 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | true, 11 | )); 12 | 13 | echo 'BINARY: SPACES' . PHP_EOL; 14 | var_dump ($binary->set ('binary key with spaces', 'this is a test')); 15 | var_dump ($binary->getResultCode () == Memcached::RES_SUCCESS); 16 | 17 | echo 'BINARY: NEWLINE' . PHP_EOL; 18 | var_dump ($binary->set ('binarykeywithnewline' . PHP_EOL, 'this is a test')); 19 | var_dump ($binary->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 20 | 21 | echo 'BINARY: EMPTY' . PHP_EOL; 22 | var_dump ($binary->set (''/*empty key*/, 'this is a test')); 23 | var_dump ($binary->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 24 | 25 | echo 'BINARY: TOO LONG' . PHP_EOL; 26 | var_dump ($binary->set (str_repeat ('1234567890', 512), 'this is a test')); 27 | var_dump ($binary->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 28 | 29 | echo 'BINARY: GET' . PHP_EOL; 30 | // Only newline fails in binary mode (char 10) 31 | for ($i=0;$i<32;$i++) { 32 | $binary->delete ('binarykeywithnonprintablechar-' . chr($i) . '-here'); 33 | var_dump ($binary->get ('binarykeywithnonprintablechar-' . chr($i) . '-here')); 34 | var_dump ($binary->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 35 | } 36 | 37 | echo 'BINARY: SET' . PHP_EOL; 38 | // Only newline fails in binary mode (char 10) 39 | for ($i=0;$i<32;$i++) { 40 | var_dump ($binary->set ('binarykeywithnonprintablechar-' . chr($i) . '-here', 'this is a test')); 41 | var_dump ($binary->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); 42 | $binary->delete ('binarykeywithnonprintablechar-' . chr($i) . '-here'); 43 | } 44 | 45 | echo 'OK' . PHP_EOL; 46 | 47 | --EXPECT-- 48 | BINARY: SPACES 49 | bool(true) 50 | bool(true) 51 | BINARY: NEWLINE 52 | bool(false) 53 | bool(true) 54 | BINARY: EMPTY 55 | bool(false) 56 | bool(true) 57 | BINARY: TOO LONG 58 | bool(false) 59 | bool(true) 60 | BINARY: GET 61 | bool(false) 62 | bool(false) 63 | bool(false) 64 | bool(false) 65 | bool(false) 66 | bool(false) 67 | bool(false) 68 | bool(false) 69 | bool(false) 70 | bool(false) 71 | bool(false) 72 | bool(false) 73 | bool(false) 74 | bool(false) 75 | bool(false) 76 | bool(false) 77 | bool(false) 78 | bool(false) 79 | bool(false) 80 | bool(false) 81 | bool(false) 82 | bool(true) 83 | bool(false) 84 | bool(false) 85 | bool(false) 86 | bool(false) 87 | bool(false) 88 | bool(false) 89 | bool(false) 90 | bool(false) 91 | bool(false) 92 | bool(false) 93 | bool(false) 94 | bool(false) 95 | bool(false) 96 | bool(false) 97 | bool(false) 98 | bool(false) 99 | bool(false) 100 | bool(false) 101 | bool(false) 102 | bool(false) 103 | bool(false) 104 | bool(false) 105 | bool(false) 106 | bool(false) 107 | bool(false) 108 | bool(false) 109 | bool(false) 110 | bool(false) 111 | bool(false) 112 | bool(false) 113 | bool(false) 114 | bool(false) 115 | bool(false) 116 | bool(false) 117 | bool(false) 118 | bool(false) 119 | bool(false) 120 | bool(false) 121 | bool(false) 122 | bool(false) 123 | bool(false) 124 | bool(false) 125 | BINARY: SET 126 | bool(true) 127 | bool(false) 128 | bool(true) 129 | bool(false) 130 | bool(true) 131 | bool(false) 132 | bool(true) 133 | bool(false) 134 | bool(true) 135 | bool(false) 136 | bool(true) 137 | bool(false) 138 | bool(true) 139 | bool(false) 140 | bool(true) 141 | bool(false) 142 | bool(true) 143 | bool(false) 144 | bool(true) 145 | bool(false) 146 | bool(false) 147 | bool(true) 148 | bool(true) 149 | bool(false) 150 | bool(true) 151 | bool(false) 152 | bool(true) 153 | bool(false) 154 | bool(true) 155 | bool(false) 156 | bool(true) 157 | bool(false) 158 | bool(true) 159 | bool(false) 160 | bool(true) 161 | bool(false) 162 | bool(true) 163 | bool(false) 164 | bool(true) 165 | bool(false) 166 | bool(true) 167 | bool(false) 168 | bool(true) 169 | bool(false) 170 | bool(true) 171 | bool(false) 172 | bool(true) 173 | bool(false) 174 | bool(true) 175 | bool(false) 176 | bool(true) 177 | bool(false) 178 | bool(true) 179 | bool(false) 180 | bool(true) 181 | bool(false) 182 | bool(true) 183 | bool(false) 184 | bool(true) 185 | bool(false) 186 | bool(true) 187 | bool(false) 188 | bool(true) 189 | bool(false) 190 | OK 191 | -------------------------------------------------------------------------------- /tests/localserver.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached local server test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set($key, array( 12 | 'foo' => 'bar' 13 | ), 360); 14 | 15 | var_dump($m->get($key)); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | ["foo"]=> 20 | string(3) "bar" 21 | } 22 | -------------------------------------------------------------------------------- /tests/memcachedserver.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MemcachedServer 3 | --SKIPIF-- 4 | 15 | --FILE-- 16 | setOption(Memcached::OPT_BINARY_PROTOCOL, true); 22 | $cache->setOption(Memcached::OPT_COMPRESSION, false); 23 | $cache->addServer('127.0.0.1', 3434); 24 | 25 | $cache->add("add_key", "hello", 500); 26 | $cache->append("append_key", "world"); 27 | $cache->prepend("prepend_key", "world"); 28 | 29 | $cache->increment("incr", 2, 1, 500); 30 | $cache->decrement("decr", 2, 1, 500); 31 | 32 | $cache->delete("delete_k"); 33 | $cache->flush(1); 34 | 35 | var_dump($cache->get('get_this')); 36 | 37 | $cache->set ('set_key', 'value 1', 100); 38 | $cache->replace ('replace_key', 'value 2', 200); 39 | 40 | var_dump($cache->getVersion()); 41 | var_dump($cache->getStats()); 42 | var_dump($cache->getStats("empty")); 43 | var_dump($cache->getStats("foobar")); 44 | var_dump($cache->getStats("scalar")); 45 | var_dump($cache->getStats("numeric array")); 46 | 47 | $cache->quit(); 48 | usleep(50000); 49 | 50 | memcached_server_stop($server); 51 | ?> 52 | Done 53 | --EXPECTF-- 54 | Listening on 127.0.0.1:3434 55 | Incoming connection from 127.0.0.1:%s 56 | Incoming connection from 127.0.0.1:%s 57 | client_id=[%s]: Add key=[add_key], value=[hello], flags=[0], expiration=[500] 58 | client_id=[%s]: Append key=[append_key], value=[world], cas=[0] 59 | client_id=[%s]: Prepend key=[prepend_key], value=[world], cas=[0] 60 | client_id=[%s]: Incrementing key=[incr], delta=[2], initial=[1], expiration=[500] 61 | client_id=[%s]: Decrementing key=[decr], delta=[2], initial=[1], expiration=[500] 62 | client_id=[%s]: Delete key=[delete_k], cas=[0] 63 | client_id=[%s]: Flush when=[1] 64 | client_id=[%s]: Get key=[get_this] 65 | client_id=[%s]: Noop 66 | string(20) "Hello to you client!" 67 | client_id=[%s]: Set key=[set_key], value=[value 1], flags=[0], expiration=[100], cas=[0] 68 | client_id=[%s]: Replace key=[replace_key], value=[value 2], flags=[0], expiration=[200], cas=[0] 69 | client_id=[%s]: Version 70 | array(1) { 71 | ["127.0.0.1:3434"]=> 72 | string(5) "1.1.1" 73 | } 74 | client_id=[%s]: Stat key=[] 75 | array(1) { 76 | ["127.0.0.1:3434"]=> 77 | array(2) { 78 | ["key"]=> 79 | string(0) "" 80 | ["foo"]=> 81 | string(3) "bar" 82 | } 83 | } 84 | client_id=[%s]: Stat key=[empty] 85 | array(0) { 86 | } 87 | client_id=[%s]: Stat key=[foobar] 88 | array(1) { 89 | ["127.0.0.1:3434"]=> 90 | array(2) { 91 | ["key"]=> 92 | string(6) "foobar" 93 | ["foo"]=> 94 | string(3) "bar" 95 | } 96 | } 97 | client_id=[%s]: Stat key=[scalar] 98 | array(1) { 99 | ["127.0.0.1:3434"]=> 100 | array(1) { 101 | [0]=> 102 | string(%d) "you want it, you get it" 103 | } 104 | } 105 | client_id=[%s]: Stat key=[numeric array] 106 | array(1) { 107 | ["127.0.0.1:3434"]=> 108 | array(3) { 109 | [-1]=> 110 | string(3) "one" 111 | [0]=> 112 | string(3) "two" 113 | [1]=> 114 | string(5) "three" 115 | } 116 | } 117 | client_id=[%s]: Client quit 118 | Done 119 | -------------------------------------------------------------------------------- /tests/memcachedserver6.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MemcachedServer 3 | --SKIPIF-- 4 | 15 | --FILE-- 16 | setOption(Memcached::OPT_BINARY_PROTOCOL, true); 22 | $cache->setOption(Memcached::OPT_COMPRESSION, false); 23 | $cache->addServer('[::1]', 3434); 24 | 25 | $cache->add("add_key", "hello", 500); 26 | $cache->append("append_key", "world"); 27 | $cache->prepend("prepend_key", "world"); 28 | 29 | $cache->increment("incr", 2, 1, 500); 30 | $cache->decrement("decr", 2, 1, 500); 31 | 32 | $cache->delete("delete_k"); 33 | $cache->flush(1); 34 | 35 | var_dump($cache->get('get_this')); 36 | 37 | $cache->set ('set_key', 'value 1', 100); 38 | $cache->replace ('replace_key', 'value 2', 200); 39 | 40 | var_dump($cache->getVersion()); 41 | var_dump($cache->getStats()); 42 | var_dump($cache->getStats("empty")); 43 | var_dump($cache->getStats("foobar")); 44 | var_dump($cache->getStats("scalar")); 45 | var_dump($cache->getStats("numeric array")); 46 | 47 | $cache->quit(); 48 | usleep(50000); 49 | 50 | memcached_server_stop($server); 51 | ?> 52 | Done 53 | --EXPECTF-- 54 | Listening on [::1]:3434 55 | Incoming connection from [::1]:%s 56 | Incoming connection from [::1]:%s 57 | client_id=[%s]: Add key=[add_key], value=[hello], flags=[0], expiration=[500] 58 | client_id=[%s]: Append key=[append_key], value=[world], cas=[0] 59 | client_id=[%s]: Prepend key=[prepend_key], value=[world], cas=[0] 60 | client_id=[%s]: Incrementing key=[incr], delta=[2], initial=[1], expiration=[500] 61 | client_id=[%s]: Decrementing key=[decr], delta=[2], initial=[1], expiration=[500] 62 | client_id=[%s]: Delete key=[delete_k], cas=[0] 63 | client_id=[%s]: Flush when=[1] 64 | client_id=[%s]: Get key=[get_this] 65 | client_id=[%s]: Noop 66 | string(20) "Hello to you client!" 67 | client_id=[%s]: Set key=[set_key], value=[value 1], flags=[0], expiration=[100], cas=[0] 68 | client_id=[%s]: Replace key=[replace_key], value=[value 2], flags=[0], expiration=[200], cas=[0] 69 | client_id=[%s]: Version 70 | array(1) { 71 | ["[::1]:3434"]=> 72 | string(5) "1.1.1" 73 | } 74 | client_id=[%s]: Stat key=[] 75 | array(1) { 76 | ["[::1]:3434"]=> 77 | array(2) { 78 | ["key"]=> 79 | string(0) "" 80 | ["foo"]=> 81 | string(3) "bar" 82 | } 83 | } 84 | client_id=[%s]: Stat key=[empty] 85 | array(0) { 86 | } 87 | client_id=[%s]: Stat key=[foobar] 88 | array(1) { 89 | ["[::1]:3434"]=> 90 | array(2) { 91 | ["key"]=> 92 | string(6) "foobar" 93 | ["foo"]=> 94 | string(3) "bar" 95 | } 96 | } 97 | client_id=[%s]: Stat key=[scalar] 98 | array(1) { 99 | ["[::1]:3434"]=> 100 | array(1) { 101 | [0]=> 102 | string(%d) "you want it, you get it" 103 | } 104 | } 105 | client_id=[%s]: Stat key=[numeric array] 106 | array(1) { 107 | ["[::1]:3434"]=> 108 | array(3) { 109 | [-1]=> 110 | string(3) "one" 111 | [0]=> 112 | string(3) "two" 113 | [1]=> 114 | string(5) "three" 115 | } 116 | } 117 | client_id=[%s]: Client quit 118 | Done 119 | -------------------------------------------------------------------------------- /tests/multi_order.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached GET_PRESERVE_ORDER flag in getMulti 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addServer (MEMC_SERVER_HOST, MEMC_SERVER_PORT); 10 | 11 | $data = array( 12 | 'foo' => 'foo-data', 13 | 'bar' => 'bar-data', 14 | 'baz' => 'baz-data', 15 | 'lol' => 'lol-data', 16 | 'kek' => 'kek-data', 17 | ); 18 | 19 | //$m->setMulti($data, 3600); 20 | foreach ($data as $k => $v) { 21 | $m->set($k, $v, 3600); 22 | } 23 | 24 | $keys = array_keys($data); 25 | $keys[] = 'zoo'; 26 | $got = $m->getMulti($keys, Memcached::GET_PRESERVE_ORDER); 27 | 28 | foreach ($got as $k => $v) { 29 | echo "$k $v\n"; 30 | } 31 | 32 | ?> 33 | --EXPECT-- 34 | foo foo-data 35 | bar bar-data 36 | baz baz-data 37 | lol lol-data 38 | kek kek-data 39 | zoo 40 | -------------------------------------------------------------------------------- /tests/no-not-found.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test that correct return value is returned 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addServer('localhost', 5555); // Server should not exist 10 | 11 | $result = $memcached->get('foo_not_exists'); 12 | var_dump ($result === Memcached::GET_ERROR_RETURN_VALUE); 13 | 14 | $result = $memcached->get('foo_not_exists'); 15 | var_dump ($result === Memcached::GET_ERROR_RETURN_VALUE); 16 | 17 | echo "OK\n"; 18 | 19 | ?> 20 | --EXPECT-- 21 | bool(true) 22 | bool(true) 23 | OK 24 | -------------------------------------------------------------------------------- /tests/options.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached options 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP); 9 | 10 | var_dump($m->getOption(Memcached::OPT_COMPRESSION)); 11 | var_dump($m->getOption(Memcached::OPT_SERIALIZER)); 12 | var_dump($m->getOption(Memcached::OPT_SOCKET_SEND_SIZE)); 13 | 14 | $m->setOption(Memcached::OPT_PREFIX_KEY, "\x01"); 15 | 16 | var_dump($m->getOption(Memcached::OPT_HASH) == Memcached::HASH_DEFAULT); 17 | $m->setOption(Memcached::OPT_HASH, Memcached::HASH_MURMUR); 18 | var_dump($m->getOption(Memcached::OPT_HASH) == Memcached::HASH_MURMUR); 19 | 20 | 21 | $m->setOption(Memcached::OPT_COMPRESSION_TYPE, Memcached::COMPRESSION_ZLIB); 22 | var_dump($m->getOption(Memcached::OPT_COMPRESSION_TYPE) == Memcached::COMPRESSION_ZLIB); 23 | 24 | $m->setOption(Memcached::OPT_COMPRESSION_TYPE, Memcached::COMPRESSION_FASTLZ); 25 | var_dump($m->getOption(Memcached::OPT_COMPRESSION_TYPE) == Memcached::COMPRESSION_FASTLZ); 26 | 27 | var_dump($m->setOption(Memcached::OPT_COMPRESSION_TYPE, 0)); 28 | var_dump($m->getOption(Memcached::OPT_COMPRESSION_TYPE) == Memcached::COMPRESSION_FASTLZ); 29 | ?> 30 | --EXPECTF-- 31 | bool(true) 32 | int(1) 33 | 34 | Warning: Memcached::getOption(): no servers defined in %s on line %d 35 | NULL 36 | 37 | Warning: Memcached::setOption(): bad key provided in %s on line %d 38 | bool(true) 39 | bool(true) 40 | bool(true) 41 | bool(true) 42 | bool(false) 43 | bool(true) 44 | -------------------------------------------------------------------------------- /tests/pr_75.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Wrong return values for binary protocol 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | true 10 | )); 11 | 12 | $client->set('key1', 'value1'); 13 | echo "set result code: ".$client->getResultCode()."\n"; 14 | 15 | $value = $client->get('key1'); 16 | echo "got $value with result code: ".$client->getResultCode()."\n"; 17 | 18 | var_dump ($client->add('key2', 'value2')); 19 | echo "add result code: ".$client->getResultCode()."\n"; 20 | 21 | echo "OK\n"; 22 | 23 | ?> 24 | --EXPECT-- 25 | set result code: 0 26 | got value1 with result code: 0 27 | bool(true) 28 | add result code: 0 29 | OK -------------------------------------------------------------------------------- /tests/prepend.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::prepend() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete('foo'); 11 | $m->setOption(Memcached::OPT_COMPRESSION, true); 12 | var_dump($m->prepend('foo', 'a')); 13 | 14 | $m->setOption(Memcached::OPT_COMPRESSION, false); 15 | $m->delete('foo'); 16 | var_dump($m->prepend('foo', 'a')); 17 | var_dump($m->get('foo')); 18 | $m->set('foo', 'a'); 19 | var_dump($m->prepend('foo', 'b')); 20 | var_dump($m->get('foo')); 21 | 22 | --EXPECTF-- 23 | Warning: Memcached::prepend(): cannot append/prepend with compression turned on in %s on line %d 24 | NULL 25 | bool(false) 26 | bool(false) 27 | bool(true) 28 | string(2) "ba" 29 | -------------------------------------------------------------------------------- /tests/replace.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::replace() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | delete('foo'); 11 | var_dump($m->replace('foo', 'bar', 60)); 12 | var_dump($m->get('foo')); 13 | 14 | $m->set('foo', 'kef'); 15 | var_dump($m->replace('foo', 'bar', 60)); 16 | var_dump($m->get('foo')); 17 | 18 | --EXPECT-- 19 | bool(false) 20 | bool(false) 21 | bool(true) 22 | string(3) "bar" 23 | -------------------------------------------------------------------------------- /tests/rescode.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached result codes. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getResultMessage(), "\n"; 11 | 12 | $m->addServer(MEMC_SERVER_HOST, MEMC_SERVER_PORT, 1); 13 | echo $m->getResultCode(), "\n"; 14 | echo $m->getResultMessage(), "\n"; 15 | 16 | $m->set('bar_foo', 10); 17 | echo $m->getResultMessage(), "\n"; 18 | 19 | $m->delete('bar_foo'); 20 | echo $m->getResultMessage(), "\n"; 21 | 22 | $m->delete('bar_foo'); 23 | echo $m->getResultCode(), "\n"; 24 | echo $m->getResultMessage(), "\n"; 25 | 26 | $m->set ('asdf_a', 'aa'); 27 | $m->getMulti(array('asdf_a', 'jkhjkhjkb', 'nbahsdgc')); 28 | echo $m->getResultMessage(), "\n"; 29 | $code = $m->getResultCode(); 30 | 31 | $m2 = new Memcached(); 32 | $m2->getMulti(array('asdf_a', 'jkhjkhjkb', 'nbahsdgc')); 33 | echo $m2->getResultCode(), "\n"; 34 | echo $m2->getResultMessage(), "\n"; 35 | 36 | $m2->addServer('127.0.0.1', 7312, 1); 37 | echo $m2->getResultCode(), "\n"; 38 | echo $m2->getResultMessage(), "\n"; 39 | 40 | $m2->delete('bar_foo'); 41 | echo $m2->getResultCode(), "\n"; 42 | echo $m2->getResultMessage(), "\n"; 43 | 44 | var_dump($m->getResultCode() == $code); 45 | 46 | $m = memc_get_instance (array (), 'test1'); 47 | $m2 = new Memcached('test1'); 48 | 49 | $m->delete('moikkamitakuuluu'); 50 | echo $m->getResultMessage(), "\n"; 51 | $m2->set('minapaasetannih', 10, 1); 52 | echo $m->getResultMessage(), "\n"; 53 | echo $m2->getResultMessage(), "\n"; 54 | 55 | $m->delete('bar_foo'); 56 | // clearly "NOT FOUND" 57 | $m->delete('bar_foo'); 58 | $res_m = $m->getResultMessage(); 59 | echo $res_m, "\n"; 60 | 61 | $m2->set('bar_foo', 10); 62 | echo $m->getResultMessage(), "\n"; 63 | echo $m2->getResultMessage(), "\n"; 64 | 65 | $m->delete('bar_foo'); 66 | echo $m->getResultMessage(), "\n"; 67 | 68 | ?> 69 | --EXPECTF-- 70 | SUCCESS 71 | %d 72 | SUCCESS 73 | SUCCESS 74 | SUCCESS 75 | %d 76 | NOT FOUND 77 | SUCCESS 78 | %d 79 | NO SERVERS DEFINED 80 | %d 81 | SUCCESS 82 | %d 83 | %rSYSTEM ERROR|WRITE FAILURE|CONNECTION FAILURE%r 84 | bool(true) 85 | NOT FOUND 86 | NOT FOUND 87 | SUCCESS 88 | NOT FOUND 89 | NOT FOUND 90 | SUCCESS 91 | SUCCESS 92 | -------------------------------------------------------------------------------- /tests/reset_keyprefix.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Cannot reset OPT_PREFIX_KEY #293 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set('key1', 'abc'); 12 | var_dump($m->get('key1')); 13 | 14 | $m->setOption(Memcached::OPT_PREFIX_KEY, 'prefix'); 15 | var_dump($m->get('key1')); 16 | 17 | $m->setOption(Memcached::OPT_PREFIX_KEY, false); 18 | var_dump($m->get('key1')); 19 | 20 | $m->setOption(Memcached::OPT_PREFIX_KEY, 'prefix'); 21 | var_dump($m->get('key1')); 22 | 23 | $m->setOption(Memcached::OPT_PREFIX_KEY, ''); 24 | var_dump($m->get('key1')); 25 | 26 | $m->setOption(Memcached::OPT_PREFIX_KEY, 'prefix'); 27 | var_dump($m->get('key1')); 28 | 29 | $m->setOption(Memcached::OPT_PREFIX_KEY, null); 30 | var_dump($m->get('key1')); 31 | --EXPECTF-- 32 | string(3) "abc" 33 | bool(false) 34 | string(3) "abc" 35 | bool(false) 36 | string(3) "abc" 37 | bool(false) 38 | string(3) "abc" -------------------------------------------------------------------------------- /tests/sasl_basic.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test SASL authentication 3 | --SKIPIF-- 4 | 10 | --INI-- 11 | memcached.use_sasl = on 12 | --FILE-- 13 | true 17 | )); 18 | 19 | var_dump ($m->setSaslAuthData (MEMC_SASL_USER, MEMC_SASL_PASS)); 20 | 21 | $key = uniqid ('sasl_test_'); 22 | var_dump ($m->set ($key, 'set using sasl')); 23 | var_dump ($m->get ($key)); 24 | 25 | 26 | echo "OK" . PHP_EOL; 27 | ?> 28 | --EXPECT-- 29 | bool(true) 30 | bool(true) 31 | string(14) "set using sasl" 32 | OK 33 | -------------------------------------------------------------------------------- /tests/server.inc: -------------------------------------------------------------------------------- 1 | STDIN, 8 | 1 => STDOUT, 9 | 2 => STDERR, 10 | ); 11 | 12 | $cmd = "{$php_executable} {$php_args} {$code} {$host}:{$port} "; 13 | if (substr(PHP_OS, 0, 3) == 'WIN') { 14 | $cmd = "{$php_executable} {$php_args} {$code} {$host}:{$port} "; 15 | 16 | $handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, __DIR__, NULL, array("bypass_shell" => true, "suppress_errors" => true)); 17 | } else { 18 | $cmd = "exec {$cmd} 2>/dev/null"; 19 | 20 | $handle = proc_open($cmd, $descriptorspec, $pipes, __DIR__); 21 | } 22 | 23 | // note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.' 24 | // it might not be listening yet...need to wait until fsockopen() call returns 25 | $error = "Unable to connect to server\n"; 26 | for ($i=0; $i < getenv("VALGRIND") ? 1000 : 60; $i++) { 27 | usleep(50000); // 50ms per try 28 | $status = proc_get_status($handle); 29 | $fp = @fsockopen($host, $port); 30 | // Failure, the server is no longer running 31 | if (!($status && $status['running'])) { 32 | $error = "Server is not running {$status['command']}\n"; 33 | break; 34 | } 35 | // Success, Connected to servers 36 | if ($fp) { 37 | $error = ''; 38 | break; 39 | } 40 | } 41 | 42 | if ($fp) { 43 | fclose($fp); 44 | } 45 | 46 | if ($error) { 47 | echo $error; 48 | proc_terminate($handle); 49 | proc_close($handle); 50 | exit(1); 51 | } 52 | 53 | register_shutdown_function( 54 | function($handle) { 55 | if (is_resource($handle)) { 56 | proc_terminate($handle); 57 | proc_close($handle); 58 | } 59 | }, 60 | $handle 61 | ); 62 | 63 | return $handle; 64 | } 65 | 66 | function memcached_server_stop($handle) { 67 | $success = FALSE; 68 | if ($handle) { 69 | proc_terminate($handle); 70 | /* Wait for server to shutdown */ 71 | for ($i = 0; $i < 60; $i++) { 72 | $status = proc_get_status($handle); 73 | if (!($status && $status['running'])) { 74 | $success = TRUE; 75 | break; 76 | } 77 | usleep(50000); 78 | } 79 | proc_close($handle); 80 | } 81 | return $success; 82 | } 83 | -------------------------------------------------------------------------------- /tests/session_badconf_emptyprefix.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Session bad configurations, prefix 3 | --SKIPIF-- 4 | 8 | --INI-- 9 | memcached.sess_locking = on 10 | memcached.sess_prefix = "memc.sess.key." 11 | session.save_handler = "memcached" 12 | 13 | --FILE-- 14 | 7 | --INI-- 8 | memcached.sess_locking = on 9 | memcached.sess_lock_wait = -1 10 | memcached.sess_prefix = "memc.sess.key." 11 | session.save_path="127.0.0.1:51312" 12 | session.save_handler = memcached 13 | 14 | --FILE-- 15 | 8 | --INI-- 9 | session.save_handler = "memcached" 10 | session.save_path = "PERSISTENT=1 hello:11211,world:11211" 11 | 12 | --FILE-- 13 | 8 | --INI-- 9 | session.save_handler = memcached 10 | --FILE-- 11 | 9 | --INI-- 10 | session.save_handler = memcached 11 | --FILE-- 12 | 70100) print "skip"; 8 | ?> 9 | --INI-- 10 | session.save_handler = memcached 11 | --FILE-- 12 | 8 | --INI-- 9 | session.save_handler = memcached 10 | memcached.sess_binary_protocol = Off 11 | --FILE-- 12 | 41 | int(1) 42 | } 43 | array(0) { 44 | } 45 | -------------------------------------------------------------------------------- /tests/session_basic2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Session basic open, write, destroy 3 | --SKIPIF-- 4 | 8 | --INI-- 9 | session.save_handler = memcached 10 | memcached.sess_binary_protocol = Off 11 | --FILE-- 12 | TRUE]); 19 | $_SESSION['foo'] = 1; 20 | session_write_close(); 21 | 22 | $_SESSION = NULL; 23 | 24 | var_dump($_SESSION); 25 | session_start(); 26 | var_dump($_SESSION); 27 | session_write_close(); 28 | 29 | session_start(); 30 | session_destroy(); 31 | 32 | session_start(); 33 | var_dump($_SESSION); 34 | session_write_close(); 35 | 36 | 37 | --EXPECT-- 38 | NULL 39 | array(1) { 40 | ["foo"]=> 41 | int(1) 42 | } 43 | array(0) { 44 | } 45 | -------------------------------------------------------------------------------- /tests/session_basic3.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Session basic open, write, destroy 3 | --SKIPIF-- 4 | 8 | --INI-- 9 | session.save_handler = memcached 10 | memcached.sess_binary_protocol = Off 11 | --FILE-- 12 | true 27 | ]); 28 | var_dump($_SESSION); 29 | session_write_close(); 30 | 31 | session_start(); 32 | session_destroy(); 33 | 34 | session_start(); 35 | var_dump($_SESSION); 36 | session_write_close(); 37 | 38 | 39 | --EXPECT-- 40 | NULL 41 | array(1) { 42 | ["foo"]=> 43 | int(1) 44 | } 45 | array(0) { 46 | } 47 | -------------------------------------------------------------------------------- /tests/session_lazy_warning.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Session lazy binary warning old libmemcached 3 | --SKIPIF-- 4 | = 0x01000018) die ('skip too recent libmemcached'); 8 | ?> 9 | --INI-- 10 | session.save_handler = memcached 11 | memcached.sess_binary_protocol = On 12 | --FILE-- 13 | TRUE]); 20 | $_SESSION['foo'] = 1; 21 | session_write_close(); 22 | 23 | $_SESSION = NULL; 24 | 25 | var_dump($_SESSION); 26 | session_start(); 27 | var_dump($_SESSION); 28 | session_write_close(); 29 | 30 | session_start(); 31 | session_destroy(); 32 | 33 | session_start(); 34 | var_dump($_SESSION); 35 | session_write_close(); 36 | 37 | 38 | --EXPECTF-- 39 | NULL 40 | array(1) { 41 | ["foo"]=> 42 | int(1) 43 | } 44 | 45 | Warning: session_write_close(): using touch command with binary protocol is not recommended with libmemcached versions below 1.0.18, please use ascii protocol or upgrade libmemcached in %s on line %d 46 | array(0) { 47 | } 48 | -------------------------------------------------------------------------------- /tests/session_lock-php71.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Session lock 3 | --SKIPIF-- 4 | 10 | --INI-- 11 | memcached.sess_locking = true 12 | memcached.sess_lock_wait_min = 500 13 | memcached.sess_lock_wait_max = 1000 14 | memcached.sess_lock_retries = 3 15 | memcached.sess_prefix = "memc.test." 16 | 17 | # Turn off binary protocol while the test matrix has older versions of 18 | # libmemcached for which the extension warns of a broken touch command. 19 | memcached.sess_binary_protocol = Off 20 | 21 | session.save_handler = memcached 22 | 23 | --FILE-- 24 | addServer(MEMC_SERVER_HOST, MEMC_SERVER_PORT); 30 | 31 | ob_start(); 32 | ini_set ('session.save_path', MEMC_SERVER_HOST . ':' . MEMC_SERVER_PORT); 33 | 34 | session_start(); 35 | $session_id = session_id(); 36 | 37 | $_SESSION["test"] = "hello"; 38 | session_write_close(); 39 | 40 | session_start(); 41 | var_dump ($m->get ('memc.test.' . session_id())); 42 | var_dump ($m->get ('memc.test.lock.' . session_id())); 43 | session_write_close(); 44 | var_dump ($m->get ('memc.test.lock.' . session_id())); 45 | 46 | // Test lock min / max 47 | $m->set ('memc.test.lock.' . $session_id, '1'); 48 | 49 | $time_start = microtime(true); 50 | session_start(); 51 | $time = microtime(true) - $time_start; 52 | 53 | if (round ($time, 1) != 2.5) { 54 | echo "Waited longer than expected: $time" . PHP_EOL; 55 | } 56 | echo "OK"; 57 | 58 | --EXPECTF-- 59 | string(17) "test|s:5:"hello";" 60 | string(1) "1" 61 | bool(false) 62 | 63 | Warning: session_start(): Unable to clear session lock record in %s on line %d 64 | 65 | Warning: session_start(): Failed to read session data: memcached (path: 127.0.0.1:11211) in %s on line %d 66 | OK 67 | -------------------------------------------------------------------------------- /tests/session_lock.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Session lock 3 | --SKIPIF-- 4 | = 70100) print "skip"; 9 | ?> 10 | --INI-- 11 | memcached.sess_locking = true 12 | memcached.sess_lock_wait_min = 500 13 | memcached.sess_lock_wait_max = 1000 14 | memcached.sess_lock_retries = 3 15 | memcached.sess_prefix = "memc.test." 16 | 17 | # Turn off binary protocol while the test matrix has older versions of 18 | # libmemcached for which the extension warns of a broken touch command. 19 | memcached.sess_binary_protocol = Off 20 | 21 | session.save_handler = memcached 22 | 23 | --FILE-- 24 | addServer(MEMC_SERVER_HOST, MEMC_SERVER_PORT); 30 | 31 | ob_start(); 32 | ini_set ('session.save_path', MEMC_SERVER_HOST . ':' . MEMC_SERVER_PORT); 33 | 34 | session_start(); 35 | $session_id = session_id(); 36 | 37 | $_SESSION["test"] = "hello"; 38 | session_write_close(); 39 | 40 | session_start(); 41 | var_dump ($m->get ('memc.test.' . session_id())); 42 | var_dump ($m->get ('memc.test.lock.' . session_id())); 43 | session_write_close(); 44 | var_dump ($m->get ('memc.test.lock.' . session_id())); 45 | 46 | // Test lock min / max 47 | $m->set ('memc.test.lock.' . $session_id, '1'); 48 | 49 | $time_start = microtime(true); 50 | session_start(); 51 | $time = microtime(true) - $time_start; 52 | 53 | if (round ($time, 1) != 2.5) { 54 | echo "Waited longer than expected: $time" . PHP_EOL; 55 | } 56 | echo "OK"; 57 | 58 | --EXPECTF-- 59 | string(17) "test|s:5:"hello";" 60 | string(1) "1" 61 | bool(false) 62 | 63 | Warning: session_start(): Unable to clear session lock record in %s on line %d 64 | OK 65 | -------------------------------------------------------------------------------- /tests/session_persistent.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Session persistent 3 | --SKIPIF-- 4 | 9 | --INI-- 10 | session.save_handler=memcached 11 | memcached.sess_persistent=1 12 | --FILE-- 13 | 24 | --EXPECT-- 25 | array(1) { 26 | ["test"]=> 27 | bool(true) 28 | } 29 | -------------------------------------------------------------------------------- /tests/session_regenerate.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Session regenerate 3 | --SKIPIF-- 4 | 8 | --INI-- 9 | session.save_handler = memcached 10 | --FILE-- 11 | 12 | --INI-- 13 | session.save_handler=memcached 14 | memcached.sess_use_tls = on 15 | memcached.sess_persistent=1 16 | 17 | --FILE-- 18 | 40 | --EXPECT-- 41 | array(1) { 42 | ["test"]=> 43 | bool(true) 44 | } 45 | OK 46 | -------------------------------------------------------------------------------- /tests/set_encoding_key.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test libmemcached encryption 3 | --SKIPIF-- 4 | 10 | --FILE-- 11 | setEncodingKey("Hello")); 17 | var_dump ($m->set ($key, 'set using encoding')); 18 | var_dump ($m->get ($key)); 19 | 20 | echo "OK" . PHP_EOL; 21 | 22 | # Change the encryption key. The old value will be inaccessible. 23 | var_dump ($m->setEncodingKey("World")); 24 | var_dump ($m->get ($key)); 25 | 26 | echo "OK" . PHP_EOL; 27 | 28 | # Restore the original key to retrieve old values again. 29 | var_dump ($m->setEncodingKey("Hello")); 30 | var_dump ($m->get ($key)); 31 | 32 | echo "OK" . PHP_EOL; 33 | 34 | # With a new encoding key we can still write new values, 35 | # this works as expected with libmemcached 1.0.18 and higher. 36 | var_dump ($m->setEncodingKey("World")); 37 | var_dump ($m->get ($key)); 38 | var_dump ($m->set ($key, 'set using encoding')); 39 | var_dump ($m->get ($key)); 40 | 41 | echo "OK" . PHP_EOL; 42 | 43 | ?> 44 | --EXPECT-- 45 | bool(true) 46 | bool(true) 47 | string(18) "set using encoding" 48 | OK 49 | bool(true) 50 | bool(false) 51 | OK 52 | bool(true) 53 | string(18) "set using encoding" 54 | OK 55 | bool(true) 56 | bool(false) 57 | bool(true) 58 | string(18) "set using encoding" 59 | OK 60 | -------------------------------------------------------------------------------- /tests/set_encoding_key2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test libmemcached encryption 3 | --SKIPIF-- 4 | = 0x01000018) die ("skip test for libmemcached lower than 1.0.18"); 9 | ?> 10 | --FILE-- 11 | setEncodingKey("Hello")); 17 | var_dump ($m->set ($key, 'set using encoding')); 18 | var_dump ($m->get ($key)); 19 | 20 | echo "OK" . PHP_EOL; 21 | 22 | # libmemcached < 1.0.18 goes into a bad state when the encoding key is changed, 23 | # so php-memcached warns and returns false when trying to change the key. 24 | var_dump ($m->setEncodingKey("World")); 25 | 26 | echo "OK" . PHP_EOL; 27 | 28 | ?> 29 | --EXPECTF-- 30 | bool(true) 31 | bool(true) 32 | string(18) "set using encoding" 33 | OK 34 | 35 | Warning: Memcached::setEncodingKey(): libmemcached versions less than 1.0.18 cannot change encoding key in %s on line %d 36 | bool(false) 37 | OK 38 | -------------------------------------------------------------------------------- /tests/set_large.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | set large data 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set($key, $value, 360)); 13 | var_dump($m->get($key) === $value); 14 | ?> 15 | --EXPECT-- 16 | bool(true) 17 | bool(true) 18 | -------------------------------------------------------------------------------- /tests/setmulti.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached::setMulti() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | deleteMulti($keys); 26 | echo "set keys: "; 27 | var_dump($m->setMulti($data, 10)); 28 | 29 | echo "get: "; 30 | $r = $m->getMulti($keys); 31 | var_dump($r); 32 | 33 | echo "Equal: "; 34 | var_dump($r === $data); 35 | 36 | --EXPECTF-- 37 | Data: array(%d) { 38 | ["foo"]=> 39 | string(3) "bar" 40 | [%i]=> 41 | string(7) "int-max" 42 | [%i]=> 43 | string(7) "int-min" 44 | [%i]=> 45 | string(7) "int-min" 46 | [0]=> 47 | string(4) "zero" 48 | [123]=> 49 | string(11) "onetwothree" 50 | [-123]=> 51 | string(14) "negonetwothree" 52 | } 53 | set keys: bool(true) 54 | get: array(%d) { 55 | ["foo"]=> 56 | string(3) "bar" 57 | [%i]=> 58 | string(7) "int-max" 59 | [%i]=> 60 | string(7) "int-min" 61 | [%i]=> 62 | string(7) "int-min" 63 | [0]=> 64 | string(4) "zero" 65 | [123]=> 66 | string(11) "onetwothree" 67 | [-123]=> 68 | string(14) "negonetwothree" 69 | } 70 | Equal: bool(true) 71 | -------------------------------------------------------------------------------- /tests/setoptions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Set options using setOptions 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setOptions(array( 11 | Memcached::OPT_PREFIX_KEY => 'a_prefix', 12 | Memcached::OPT_SERIALIZER => Memcached::SERIALIZER_PHP, 13 | Memcached::OPT_COMPRESSION => 0, 14 | Memcached::OPT_LIBKETAMA_COMPATIBLE => 1, 15 | Memcached::OPT_CONNECT_TIMEOUT => 5000, 16 | ))); 17 | 18 | var_dump($m->getOption(Memcached::OPT_PREFIX_KEY) == 'a_prefix'); 19 | var_dump($m->getOption(Memcached::OPT_SERIALIZER) == Memcached::SERIALIZER_PHP); 20 | var_dump($m->getOption(Memcached::OPT_COMPRESSION) == 0); 21 | var_dump($m->getOption(Memcached::OPT_LIBKETAMA_COMPATIBLE) == 1); 22 | 23 | echo "test invalid options\n"; 24 | 25 | var_dump($m->setOptions(array( 26 | "asdf" => 123 27 | ))); 28 | 29 | var_dump($m->setOptions(array( 30 | -1 => 123 31 | ))); 32 | 33 | --EXPECTF-- 34 | bool(true) 35 | bool(true) 36 | bool(true) 37 | bool(true) 38 | bool(true) 39 | test invalid options 40 | 41 | Warning: Memcached::setOptions(): invalid configuration option in %s on line %d 42 | bool(false) 43 | 44 | Warning: Memcached::setOptions(): error setting memcached option: %s in %s on line %d 45 | bool(false) 46 | -------------------------------------------------------------------------------- /tests/skipif.inc: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | getStats(); 11 | $key = MEMC_SERVER_HOST . ':' . MEMC_SERVER_PORT; 12 | 13 | var_dump (count ($stats) === 1); 14 | var_dump (isset ($stats[$key])); 15 | var_dump (count ($stats[$key]) > 0); 16 | var_dump (is_int ($stats[$key]['cmd_get'])); 17 | 18 | echo "OK"; 19 | ?> 20 | --EXPECT-- 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | bool(true) 25 | OK 26 | -------------------------------------------------------------------------------- /tests/stats_hang.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check stats does not hang on non-blocking binary protocol 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setOption(Memcached::OPT_NO_BLOCK, true); 14 | $m->setOption(Memcached::OPT_BINARY_PROTOCOL, true); 15 | 16 | $stats = $m->getStats(); 17 | $conns1 = $stats[$key]['total_connections']; 18 | 19 | $stats = $m->getStats(); 20 | $conns2 = $stats[$key]['total_connections']; 21 | 22 | var_dump($conns1 == $conns2); 23 | var_dump($m->getOption(Memcached::OPT_NO_BLOCK)); 24 | var_dump($m->getOption(Memcached::OPT_BINARY_PROTOCOL)); 25 | echo "OK" . PHP_EOL; 26 | 27 | // If either or both options are false no need to reconnect 28 | $m->setOption(Memcached::OPT_NO_BLOCK, false); 29 | $m->setOption(Memcached::OPT_BINARY_PROTOCOL, true); 30 | 31 | $stats = $m->getStats(); 32 | $conns1 = $stats[$key]['total_connections']; 33 | 34 | $stats = $m->getStats(); 35 | $conns2 = $stats[$key]['total_connections']; 36 | 37 | var_dump($conns1 == $conns2); 38 | var_dump($m->getOption(Memcached::OPT_NO_BLOCK)); 39 | var_dump($m->getOption(Memcached::OPT_BINARY_PROTOCOL)); 40 | echo "OK" . PHP_EOL; 41 | 42 | // If either or both options are false no need to reconnect 43 | $m->setOption(Memcached::OPT_NO_BLOCK, true); 44 | $m->setOption(Memcached::OPT_BINARY_PROTOCOL, false); 45 | 46 | $stats = $m->getStats(); 47 | $conns1 = $stats[$key]['total_connections']; 48 | 49 | $stats = $m->getStats(); 50 | $conns2 = $stats[$key]['total_connections']; 51 | 52 | var_dump($conns1 == $conns2); 53 | var_dump($m->getOption(Memcached::OPT_NO_BLOCK)); 54 | var_dump($m->getOption(Memcached::OPT_BINARY_PROTOCOL)); 55 | echo "OK" . PHP_EOL; 56 | 57 | // If either or both options are false no need to reconnect 58 | $m->setOption(Memcached::OPT_NO_BLOCK, false); 59 | $m->setOption(Memcached::OPT_BINARY_PROTOCOL, false); 60 | 61 | $stats = $m->getStats(); 62 | $conns1 = $stats[$key]['total_connections']; 63 | 64 | $stats = $m->getStats(); 65 | $conns2 = $stats[$key]['total_connections']; 66 | 67 | var_dump($conns1 == $conns2); 68 | var_dump($m->getOption(Memcached::OPT_NO_BLOCK)); 69 | var_dump($m->getOption(Memcached::OPT_BINARY_PROTOCOL)); 70 | echo "OK" . PHP_EOL; 71 | 72 | ?> 73 | --EXPECT-- 74 | bool(false) 75 | int(1) 76 | int(1) 77 | OK 78 | bool(true) 79 | int(0) 80 | int(1) 81 | OK 82 | bool(true) 83 | int(1) 84 | int(0) 85 | OK 86 | bool(true) 87 | int(0) 88 | int(0) 89 | OK 90 | -------------------------------------------------------------------------------- /tests/tls_basic.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test TLS 3 | --SKIPIF-- 4 | 11 | --INI-- 12 | 13 | --FILE-- 14 | cert_file = MEMC_TLS_CERT; 20 | $obj->key_file = MEMC_TLS_KEY; 21 | $obj->ca_cert_file = defined('MEMC_TLS_CA_FILE') ? MEMC_TLS_CA_FILE : null; 22 | $obj->skip_cert_verify = true; 23 | $obj->skip_hostname_verify = true; 24 | 25 | $m->setOption(Memcached::OPT_USE_TLS, 1); 26 | 27 | $m->createAndSetTLSContext((array)$obj); 28 | 29 | // Test basic use case of set get 30 | $m->set('key', 'value', 60); 31 | var_dump($m->get('key') == 'value'); 32 | 33 | // Make sure we failed to get key when TLS is disabled 34 | $m->setOption(Memcached::OPT_USE_TLS, 0); 35 | var_dump($m->get('key') == 'value'); 36 | 37 | // Test dynamically setting on/off TLS works 38 | $m->createAndSetTLSContext((array)$obj); 39 | $m->setOption(Memcached::OPT_USE_TLS, 1); 40 | var_dump($m->get('key') == 'value'); 41 | 42 | 43 | echo "OK" . PHP_EOL; 44 | ?> 45 | --EXPECT-- 46 | bool(true) 47 | bool(false) 48 | bool(true) 49 | OK 50 | -------------------------------------------------------------------------------- /tests/touch_binary.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Touch in binary mode 3 | --SKIPIF-- 4 | = 80200) print "skip"; 12 | ?> 13 | --FILE-- 14 | getConstants (); 20 | 21 | foreach ($c as $name => $value) { 22 | if (strpos ($name, 'RES_') === 0 && $value == $code) 23 | return $name; 24 | } 25 | } 26 | 27 | function status_print ($op, $mem, $expected) 28 | { 29 | $code = $mem->getResultcode(); 30 | 31 | if ($code == $expected) 32 | echo "${op} status code as expected" . PHP_EOL; 33 | else { 34 | $expected = resolve_to_constant ($expected); 35 | $code = resolve_to_constant ($code); 36 | 37 | echo "${op} status code mismatch, expected ${expected} but got ${code}" . PHP_EOL; 38 | } 39 | } 40 | 41 | include dirname (__FILE__) . '/config.inc'; 42 | $mem = memc_get_instance (array (Memcached::OPT_BINARY_PROTOCOL => true)); 43 | 44 | $key = uniqid ('touch_t_'); 45 | 46 | $mem->get($key); 47 | status_print ('get', $mem, Memcached::RES_NOTFOUND); 48 | 49 | $mem->set ($key, 1); 50 | status_print ('set', $mem, Memcached::RES_SUCCESS); 51 | 52 | $mem->get($key); 53 | status_print ('get', $mem, Memcached::RES_SUCCESS); 54 | 55 | $mem->touch ($key, 10); 56 | status_print ('touch', $mem, Memcached::RES_SUCCESS); 57 | 58 | $mem->get($key); 59 | status_print ('get', $mem, Memcached::RES_SUCCESS); 60 | 61 | $mem->get($key); 62 | status_print ('get', $mem, Memcached::RES_SUCCESS); 63 | 64 | echo "OK\n"; 65 | 66 | ?> 67 | --EXPECT-- 68 | get status code as expected 69 | set status code as expected 70 | get status code as expected 71 | touch status code as expected 72 | get status code as expected 73 | get status code as expected 74 | OK 75 | -------------------------------------------------------------------------------- /tests/types.inc: -------------------------------------------------------------------------------- 1 | "1","b" => "2","c" => "3")), 32 | array('object_dummy', new testclass()), 33 | ); 34 | 35 | foreach ($data as $key => $value) { 36 | $m->delete($key); 37 | } 38 | 39 | foreach ($data as $types) { 40 | $key = $types [0]; 41 | $value = $types [1]; 42 | 43 | $m->set($key, $value); 44 | 45 | $actual = $m->get($key); 46 | if ($value !== $actual) { 47 | if (is_object($actual)) { 48 | if ($options['ignore_object_type']) { 49 | $value = (object) (array) $value; 50 | if ($value == $actual) 51 | continue; 52 | } 53 | 54 | if ($value == $actual && get_class($value) == get_class($actual)) 55 | continue; 56 | } 57 | echo "=== {$key} ===\n"; 58 | echo "Expected: "; 59 | var_dump($value); 60 | echo "Actual: "; 61 | var_dump($actual); 62 | 63 | } 64 | } 65 | 66 | $m->flush(); 67 | 68 | if (($actual = $m->get(uniqid ('random_key_'))) !== false) { 69 | echo "Expected: null"; 70 | echo "Actual: " . gettype($actual); 71 | } 72 | } 73 | 74 | function memc_types_test_multi ($m, $options) 75 | { 76 | $data = array( 77 | 'boolean_true' => true, 78 | 'boolean_false' => false, 79 | 80 | 'string' => "just a string", 81 | 'string_empty' => "", 82 | 'string_large' => str_repeat ('abcdef0123456789', 500), 83 | 84 | 'integer_positive_integer' => 10, 85 | 'integer_negative_integer' => -10, 86 | 'integer_zero_integer' => 0, 87 | 88 | 'float_positive1' => 3.912131, 89 | 'float_positive2' => 1.2131E+52, 90 | 'float_negative' => -42.123312, 91 | 'float_zero' => 0.0, 92 | 93 | 'null' => null, 94 | 95 | 'array_empty' => array(), 96 | 'array' => array(1,2,3,"foo"), 97 | 98 | 'object_array_empty' => (object)array(), 99 | 'object_array' => (object)array('a' => 1, 'b' => 2, 'c' => 3), 100 | 'object_dummy' => new testclass(), 101 | ); 102 | 103 | foreach ($data as $key => $value) { 104 | $m->delete($key); 105 | } 106 | $m->setMulti($data); 107 | $actual = $m->getMulti(array_keys($data)); 108 | 109 | foreach ($data as $key => $value) { 110 | if ($value !== $actual[$key]) { 111 | if (is_object($value)) { 112 | if ($options['ignore_object_type']) { 113 | $value = (object) (array) $value; 114 | if ($value == $actual[$key]) 115 | continue; 116 | } 117 | 118 | if ($value == $actual[$key] && get_class($value) == get_class($actual[$key])) 119 | continue; 120 | } 121 | 122 | echo "=== $key ===\n"; 123 | echo "Expected: "; 124 | var_dump($value); 125 | echo "Actual: "; 126 | var_dump($actual[$key]); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /tests/types_igbinary.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached store & fetch type and value correctness using igbinary serializer 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 18 | --EXPECT-- 19 | TEST DONE 20 | -------------------------------------------------------------------------------- /tests/types_igbinary_multi.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached multi store & multi fetch type and value correctness using igbinary serializer 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 18 | --EXPECT-- 19 | TEST DONE 20 | -------------------------------------------------------------------------------- /tests/types_json.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached store & fetch type and value correctness using JSON serializer 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 18 | --EXPECT-- 19 | TEST DONE 20 | -------------------------------------------------------------------------------- /tests/types_json_multi.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached multi store & multi fetch type and value correctness using JSON serializer 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 18 | --EXPECT-- 19 | TEST DONE 20 | -------------------------------------------------------------------------------- /tests/types_msgpack.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached store & fetch type and value correctness using msgpack serializer 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 18 | --EXPECT-- 19 | TEST DONE 20 | -------------------------------------------------------------------------------- /tests/types_msgpack_multi.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached multi store & fetch type and value correctness using msgpack serializer 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 18 | --EXPECT-- 19 | TEST DONE 20 | -------------------------------------------------------------------------------- /tests/types_php.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached store & fetch type and value correctness using PHP serializer 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 15 | --EXPECT-- 16 | TEST DONE 17 | -------------------------------------------------------------------------------- /tests/types_php_multi.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached multi store & fetch type and value correctness using PHP serializer 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 15 | --EXPECT-- 16 | TEST DONE 17 | -------------------------------------------------------------------------------- /tests/undefined_set.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Set with undefined key and value 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'bar'); 12 | 13 | // silent to hide: 14 | // Warning: Undefined variable 15 | // Deprecated: Memcached::set(): Passing null to parameter (PHP 8.1) 16 | 17 | $rv = @$m->set($no_key, $value, 360); 18 | var_dump($rv); 19 | 20 | 21 | $rv = @$m->set($key, $no_value, 360); 22 | var_dump($rv); 23 | 24 | $rv = @$m->set($no_key, $no_value, 360); 25 | var_dump($rv); 26 | 27 | $rv = @$m->set($key, $value, $no_time); 28 | var_dump($rv); 29 | ?> 30 | --EXPECTF-- 31 | bool(false) 32 | bool(true) 33 | bool(false) 34 | bool(true) 35 | -------------------------------------------------------------------------------- /tests/user-flags.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached user flags 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | get($key, null, Memcached::GET_EXTENDED)['flags']; 21 | } 22 | 23 | define ('FLAG_1', 1); 24 | define ('FLAG_2', 2); 25 | define ('FLAG_4', 4); 26 | define ('FLAG_32', 32); 27 | define ('FLAG_64', 64); 28 | define ('FLAG_TOO_LARGE', pow(2, 16)); 29 | 30 | include dirname (__FILE__) . '/config.inc'; 31 | $m = memc_get_instance (array (Memcached::OPT_BINARY_PROTOCOL => true)); 32 | 33 | $key = uniqid ('udf_test_'); 34 | 35 | // Set with flags off 36 | $m->set ($key, '1', 10); 37 | $v = $m->get($key, null, Memcached::GET_EXTENDED); 38 | var_dump($v); 39 | 40 | // Set flags on 41 | $m->setOption(Memcached::OPT_USER_FLAGS, FLAG_1); 42 | $m->set ($key, '1', 10); 43 | $m->get($key); 44 | check_flags(get_flags($m, $key), array(FLAG_1)); 45 | 46 | // Multiple flags 47 | $m->setOption(Memcached::OPT_USER_FLAGS, FLAG_1 | FLAG_2 | FLAG_4); 48 | $m->set ($key, '1', 10); 49 | $m->get($key); 50 | check_flags(get_flags($m, $key), array(FLAG_1, FLAG_2, FLAG_4)); 51 | 52 | // Even more flags 53 | $m->setOption(Memcached::OPT_USER_FLAGS, FLAG_1 | FLAG_2 | FLAG_4 | FLAG_32 | FLAG_64); 54 | $m->set ($key, '1', 10); 55 | $m->get($key); 56 | check_flags(get_flags($m, $key), array(FLAG_1, FLAG_2, FLAG_4, FLAG_32, FLAG_64)); 57 | 58 | // User flags with get multi 59 | $values = array( 60 | uniqid ('udf_test_multi_') => "first", 61 | uniqid ('udf_test_multi_') => "second", 62 | uniqid ('udf_test_multi_') => "third", 63 | ); 64 | 65 | $m->setOption(Memcached::OPT_USER_FLAGS, FLAG_2 | FLAG_4); 66 | $m->setMulti($values); 67 | $m->getMulti(array_keys($values)); 68 | $flags = $m->getMulti(array_keys($values), Memcached::GET_EXTENDED); 69 | 70 | foreach (array_keys($values) as $key) { 71 | check_flags($flags[$key]['flags'], array(FLAG_2, FLAG_4)); 72 | } 73 | 74 | // User flags with compression on 75 | $m->setOption(Memcached::OPT_USER_FLAGS, FLAG_1 | FLAG_2 | FLAG_4); 76 | $m->setOption(Memcached::OPT_COMPRESSION, true); 77 | $m->setOption(Memcached::OPT_COMPRESSION_TYPE, Memcached::COMPRESSION_FASTLZ); 78 | 79 | $m->set ($key, '1', 10); 80 | $m->get($key); 81 | check_flags(get_flags($m, $key), array(FLAG_1, FLAG_2, FLAG_4)); 82 | 83 | 84 | // Too large flags 85 | $m->setOption(Memcached::OPT_USER_FLAGS, FLAG_TOO_LARGE); 86 | 87 | echo "DONE TEST\n"; 88 | ?> 89 | --EXPECTF-- 90 | array(3) { 91 | ["value"]=> 92 | string(1) "1" 93 | ["cas"]=> 94 | int(%d) 95 | ["flags"]=> 96 | int(0) 97 | } 98 | Flags OK 99 | Flags OK 100 | Flags OK 101 | Flags OK 102 | Flags OK 103 | Flags OK 104 | Flags OK 105 | 106 | Warning: Memcached::setOption(): MEMC_OPT_USER_FLAGS must be < 65535 in %s on line %d 107 | DONE TEST -------------------------------------------------------------------------------- /tests/vbucket.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached virtual buckets 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | Memcached::DISTRIBUTION_VIRTUAL_BUCKET 13 | )); 14 | 15 | var_dump ($m->setBucket (array (1, 2, 3), null, 2)); 16 | 17 | var_dump ($m->setBucket (array (1,2,2), array (1,2,2), 2)); 18 | 19 | var_dump ($m->setBucket (array ('a', 'b', 'c'), null, 2)); 20 | 21 | echo "OK\n"; 22 | 23 | ?> 24 | --EXPECTF-- 25 | bool(true) 26 | bool(true) 27 | bool(true) 28 | OK 29 | -------------------------------------------------------------------------------- /tests/vbucket_error_7.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached virtual buckets 3 | --SKIPIF-- 4 | = 80000) die("skip PHP 7 only"); 8 | ?> 9 | --FILE-- 10 | Memcached::DISTRIBUTION_VIRTUAL_BUCKET 14 | )); 15 | 16 | var_dump ($m->setBucket (array (), null, 2)); 17 | 18 | var_dump ($m->setBucket (array (), array (), -1)); 19 | 20 | var_dump ($m->setBucket (null, array (), -1)); 21 | 22 | var_dump ($m->setBucket (array (-1), array (-1), 1)); 23 | 24 | echo "OK\n"; 25 | 26 | ?> 27 | --EXPECTF-- 28 | 29 | Warning: Memcached::setBucket(): server map cannot be empty in %s on line %d 30 | bool(false) 31 | 32 | Warning: Memcached::setBucket(): server map cannot be empty in %s on line %d 33 | bool(false) 34 | 35 | Warning: Memcached::setBucket() expects parameter 1 to be array, null given in %s on line %d 36 | NULL 37 | 38 | Warning: Memcached::setBucket(): the map must contain positive integers in %s on line %d 39 | bool(false) 40 | OK 41 | -------------------------------------------------------------------------------- /tests/vbucket_error_8.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memcached virtual buckets 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | Memcached::DISTRIBUTION_VIRTUAL_BUCKET 14 | )); 15 | 16 | var_dump ($m->setBucket (array (), null, 2)); 17 | 18 | var_dump ($m->setBucket (array (), array (), -1)); 19 | 20 | try { 21 | var_dump ($m->setBucket (null, array (), -1)); 22 | } catch (TypeError $e) { 23 | echo $e->getMessage() . PHP_EOL; 24 | } 25 | 26 | var_dump ($m->setBucket (array (-1), array (-1), 1)); 27 | 28 | echo "OK\n"; 29 | 30 | ?> 31 | --EXPECTF-- 32 | Warning: Memcached::setBucket(): server map cannot be empty in %s on line %d 33 | bool(false) 34 | 35 | Warning: Memcached::setBucket(): server map cannot be empty in %s on line %d 36 | bool(false) 37 | Memcached::setBucket(): Argument #1 ($host_map) must be of type array, null given 38 | 39 | Warning: Memcached::setBucket(): the map must contain positive integers in %s on line %d 40 | bool(false) 41 | OK 42 | -------------------------------------------------------------------------------- /tests/version.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Get version 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getVersion ()); 10 | 11 | echo "OK" . PHP_EOL; 12 | ?> 13 | --EXPECTF-- 14 | array(1) { 15 | ["%s:%d"]=> 16 | string(%d) "%d.%d.%d" 17 | } 18 | OK 19 | -------------------------------------------------------------------------------- /tls-examples/memcached-tls-client.php: -------------------------------------------------------------------------------- 1 | addServer($server_endpoint, $server_port); 19 | 20 | /* enable TLS option */ 21 | if(!$tls_client->setOption(Memcached::OPT_USE_TLS, 1)) { 22 | echo $tls_client->getLastErrorMessage(), "\n"; 23 | exit(1); 24 | } 25 | 26 | /* create new TLS context configurations object and set your context values. 27 | * see MemcachedTLSContextConfig in memcached-api.php for all configurations */ 28 | $tls_config = new MemcachedTLSContextConfig(); 29 | $tls_config->cert_file = '/path/to/memc.crt'; 30 | $tls_config->key_file = '/path/to/memc.key'; 31 | $tls_config->ca_cert_file = '/path/to/ca.crt'; 32 | $tls_config->hostname = '*.example.use1.cache.amazonaws.com'; 33 | $tls_config->skip_cert_verify = false; 34 | $tls_config->skip_hostname_verify = false; 35 | 36 | /* pass the TLS configurations in order to create OpenSSL's SSL_CTX and to set it to your client. 37 | * note: all the client's servers will be configured with these TLS context configurations. */ 38 | $tls_client->createAndSetTLSContext((array)$tls_config); 39 | 40 | /* test the TLS connection with set-get scenario: */ 41 | 42 | /* store the data for 60 seconds in the cluster. 43 | * The client will decide which cache host will store this item. 44 | */ 45 | if($tls_client->set('key', 'value', 60)) { 46 | print "Successfully stored key\n"; 47 | } else { 48 | echo "Failed to set key: ", $tls_client->getLastErrorMessage(), "\n"; 49 | exit(1); 50 | } 51 | 52 | /* retrieve the key */ 53 | if ($tls_client->get('key') === 'value') { 54 | print "Successfully retrieved key\n"; 55 | } else { 56 | echo "Failed to get key: ", $tls_client->getLastErrorMessage(), "\n"; 57 | exit(1); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /tls-examples/memcached-tls-session.php: -------------------------------------------------------------------------------- 1 |