Porting to php8 (#74)

* Initial work for php 8

* php7 -> php8
This commit is contained in:
Zaffy
2020-09-24 19:27:46 +02:00
committed by GitHub
parent baec8a29aa
commit 7889bd1d23
29 changed files with 416 additions and 162 deletions

10
.gitignore vendored
View File

@@ -31,6 +31,14 @@
# Debug files
*.dSYM/
# Tests-generated stuff
tests/*.diff
tests/*.php
tests/*.out
tests/*.sh
tests/*.log
tests/*.exp
*.fragments
Makefile*
autom4te*
@@ -55,6 +63,6 @@ mkinstalldirs
run-tests.php
fails.log
configure.ac
tests/*.php
*.code-workspace
.vscode/*
.idea/

View File

@@ -1,4 +1,4 @@
ARG PHP_IMAGE=php:7.4-rc
ARG PHP_IMAGE=php:8.0-rc
FROM $PHP_IMAGE
RUN apt-get update && apt-get install -y \
@@ -8,5 +8,7 @@ RUN apt-get update && apt-get install -y \
COPY docker/host.conf /etc/host.conf
# ENV LOCAL_DEV 1
# ADD . /usr/src/pecl-memcache
COPY docker/start.sh /
CMD ["/start.sh"]

2
README
View File

@@ -1,6 +1,6 @@
This is an official repository for pecl-memcache plugin since 2019.
This repository contains modified pecl-memcache plugin ported to PHP7,
This repository contains modified pecl-memcache plugin ported to PHP8,
which was originally developed for the need of hosting company in Slovakia (Websupport.sk).
The latest release is 4.0.5.1 (released: 2019-12-19) with support for PHP 7.0-7.4.

View File

@@ -9,8 +9,8 @@ if (PHP_MEMCACHE != "no") {
var dll = get_define('PHPDLL');
var old_conf_dir = configure_module_dirname;
if (dll.match(/^php7/) != null) {
configure_module_dirname = configure_module_dirname + "\\php7";
if (dll.match(/^php8/) != null) {
configure_module_dirname = configure_module_dirname + "\\php8";
} else if (dll.match(/^php5/) != null) {
ERROR("PHP 7.x required for pecl-php-memcache ver 4+. Use pecl-php-meachce ver 3.x for PHP 5.x.");
} else {

View File

@@ -64,7 +64,7 @@ if test "$PHP_MEMCACHE" != "no"; then
fi
AC_MSG_CHECKING(PHP version)
if test -d $abs_srcdir/php7 ; then
if test -d $abs_srcdir/php8 ; then
dnl # only when for PECL, not for PHP
export OLD_CPPFLAGS="$CPPFLAGS"
export CPPFLAGS="$CPPFLAGS $INCLUDES"
@@ -73,7 +73,7 @@ if test "$PHP_MEMCACHE" != "no"; then
#error "PHP < 7"
#endif
], [
subdir=php7
subdir=php8
AC_MSG_RESULT([PHP 7.x])
],
AC_MSG_ERROR([PHP 7.x required for pecl-php-memcache ver 4+. Use pecl-php-memcache ver 3.x for PHP 5.x.])

View File

@@ -1,9 +1,8 @@
#!/bin/bash
CFLAGS="-fstack-protector-strong -fpic -fpie -O2"
CPPFLAGS="$PHP_CFLAGS"
LDFLAGS="-Wl,-O1 -Wl,--hash-style=both -pie"
export CFLAGS="-fstack-protector-strong -O2"
export CPPFLAGS="${CFLAGS}"
export LDFLAGS="-Wl,-O1 -Wl,--hash-style=both"
# Build extension
set -eux
@@ -14,10 +13,11 @@ then
git clone https://github.com/websupport-sk/pecl-memcache.git
fi
cd pecl-memcache;
phpize
cd pecl-memcache;
[[ -n "${LOCAL_DEV}" ]] && phpize --clean
phpize
./configure
make -j$(nproc)
make -j"$(nproc)"
# Spawn memcached for tests
echo "Starting memcached... "
@@ -29,4 +29,4 @@ chown memcache:memcache /var/run/memcached
# Let's start tests
cd /usr/src/pecl-memcache
TEST_PHP_ARGS="--show-diff --keep-all -w fails.log" make test
NO_INTERACTION=1 TEST_PHP_ARGS="--show-diff --keep-all -w fails.log" make test

View File

@@ -66,7 +66,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file name="host.conf" role="src" />
<file name="start.sh" role="src" />
</dir>
<dir name="php7">
<dir name="php8">
<file name="memcache.c" role="src" />
<file name="memcache_pool.c" role="src" />
<file name="memcache_queue.c" role="src" />

View File

@@ -26,7 +26,6 @@
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "ext/standard/php_string.h"
#include "php_memcache.h"
/* True global resources - no need for thread safety here */
@@ -38,80 +37,276 @@ ZEND_EXTERN_MODULE_GLOBALS(memcache)
/* {{{ memcache_functions[]
*/
ZEND_BEGIN_ARG_INFO(arginfo_memcache_get, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_ARG_PASS_INFO(1)
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_connect, 0, 0, 1)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, udp_port)
ZEND_ARG_INFO(0, persistent)
ZEND_ARG_INFO(0, weight)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, retry_interval)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_memcache_object_get, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_ARG_PASS_INFO(1)
#define arginfo_memcache_pconnect arginfo_memcache_connect
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_add_server, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, persistent)
ZEND_ARG_INFO(0, weight)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, retry_interval)
ZEND_ARG_INFO(0, status)
ZEND_ARG_INFO(0, failure_callback)
ZEND_ARG_INFO(0, timeoutms)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_set_server_params, 0, 0, 1)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, retry_interval)
ZEND_ARG_INFO(0, status)
ZEND_ARG_INFO(0, failure_callback)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_set_failure_callback, 1, 0, 2)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, failure_callback)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_get_server_status, 0, 0, 1)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_get_version, 1, 0, 1)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_add, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, flag)
ZEND_ARG_INFO(0, exptime)
ZEND_END_ARG_INFO()
#define arginfo_memcache_set arginfo_memcache_add
#define arginfo_memcache_replace arginfo_memcache_add
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_cas, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, flag)
ZEND_ARG_INFO(0, exptime)
ZEND_ARG_INFO(0, cas)
ZEND_END_ARG_INFO()
#define arginfo_memcache_append arginfo_memcache_add
#define arginfo_memcache_prepend arginfo_memcache_add
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_get, 1, 0, 2)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(1, flags)
ZEND_ARG_INFO(1, cas)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_delete, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, exptime)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_debug, 0, 0, 1)
ZEND_ARG_INFO(0, on_off)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_get_stats, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, slabid)
ZEND_ARG_INFO(0, limit)
ZEND_END_ARG_INFO()
#define arginfo_memcache_get_extended_stats arginfo_memcache_get_stats
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_set_compress_threshold, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, threshold)
ZEND_ARG_INFO(0, min_savings)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_increment, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, defval)
ZEND_ARG_INFO(0, exptime)
ZEND_END_ARG_INFO()
#define arginfo_memcache_decrement arginfo_memcache_increment
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_close, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_flush, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, delay)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_set_sasl_auth_data, 1, 0, 3)
ZEND_ARG_OBJ_INFO(0, memcache, MemcachePool, 0)
ZEND_ARG_INFO(0, username)
ZEND_ARG_INFO(0, password)
ZEND_END_ARG_INFO()
zend_function_entry memcache_functions[] = {
PHP_FE(memcache_connect, NULL)
PHP_FE(memcache_pconnect, NULL)
PHP_FE(memcache_add_server, NULL)
PHP_FE(memcache_set_server_params, NULL)
PHP_FE(memcache_set_failure_callback, NULL)
PHP_FE(memcache_get_server_status, NULL)
PHP_FE(memcache_get_version, NULL)
PHP_FE(memcache_add, NULL)
PHP_FE(memcache_set, NULL)
PHP_FE(memcache_replace, NULL)
PHP_FE(memcache_cas, NULL)
PHP_FE(memcache_append, NULL)
PHP_FE(memcache_prepend, NULL)
PHP_FE(memcache_connect, arginfo_memcache_connect)
PHP_FE(memcache_pconnect, arginfo_memcache_pconnect)
PHP_FE(memcache_add_server, arginfo_memcache_add_server)
PHP_FE(memcache_set_server_params, arginfo_memcache_set_server_params)
PHP_FE(memcache_set_failure_callback, arginfo_memcache_set_failure_callback)
PHP_FE(memcache_get_server_status, arginfo_memcache_get_server_status)
PHP_FE(memcache_get_version, arginfo_memcache_get_version)
PHP_FE(memcache_add, arginfo_memcache_add)
PHP_FE(memcache_set, arginfo_memcache_set)
PHP_FE(memcache_replace, arginfo_memcache_replace)
PHP_FE(memcache_cas, arginfo_memcache_cas)
PHP_FE(memcache_append, arginfo_memcache_append)
PHP_FE(memcache_prepend, arginfo_memcache_prepend)
PHP_FE(memcache_get, arginfo_memcache_get)
PHP_FE(memcache_delete, NULL)
PHP_FE(memcache_debug, NULL)
PHP_FE(memcache_get_stats, NULL)
PHP_FE(memcache_get_extended_stats, NULL)
PHP_FE(memcache_set_compress_threshold, NULL)
PHP_FE(memcache_increment, NULL)
PHP_FE(memcache_decrement, NULL)
PHP_FE(memcache_close, NULL)
PHP_FE(memcache_flush, NULL)
PHP_FE(memcache_set_sasl_auth_data, NULL)
{NULL, NULL, NULL}
PHP_FE(memcache_delete, arginfo_memcache_delete)
PHP_FE(memcache_debug, arginfo_memcache_debug)
PHP_FE(memcache_get_stats, arginfo_memcache_get_stats)
PHP_FE(memcache_get_extended_stats, arginfo_memcache_get_extended_stats)
PHP_FE(memcache_set_compress_threshold, arginfo_memcache_set_compress_threshold)
PHP_FE(memcache_increment, arginfo_memcache_increment)
PHP_FE(memcache_decrement, arginfo_memcache_decrement)
PHP_FE(memcache_close, arginfo_memcache_close)
PHP_FE(memcache_flush, arginfo_memcache_flush)
PHP_FE(memcache_set_sasl_auth_data, arginfo_memcache_set_sasl_auth_data)
ZEND_FE_END
};
#define arginfo_memcache_object_connect arginfo_memcache_connect
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_addserver, 0, 0, 1)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, persistent)
ZEND_ARG_INFO(0, weight)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, retry_interval)
ZEND_ARG_INFO(0, status)
ZEND_ARG_INFO(0, failure_callback)
ZEND_ARG_INFO(0, timeoutms)
ZEND_END_ARG_INFO()
#define arginfo_memcache_object_setserverparams arginfo_memcache_set_server_params
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_setfailurecallback, 0, 0, 1)
ZEND_ARG_INFO(0, failure_callback)
ZEND_END_ARG_INFO()
#define arginfo_memcache_object_getserverstatus arginfo_memcache_get_server_status
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_findserver, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_getversion, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_add, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, flag)
ZEND_ARG_INFO(0, exptime)
ZEND_END_ARG_INFO()
#define arginfo_memcache_object_set arginfo_memcache_object_add
#define arginfo_memcache_object_replace arginfo_memcache_object_add
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_cas, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, flag)
ZEND_ARG_INFO(0, exptime)
ZEND_ARG_INFO(0, cas)
ZEND_END_ARG_INFO()
#define arginfo_memcache_object_append arginfo_memcache_object_add
#define arginfo_memcache_object_prepend arginfo_memcache_object_add
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_get, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(1, flags)
ZEND_ARG_INFO(1, cas)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_delete, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, exptime)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_getstats, 0, 0, 0)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, slabid)
ZEND_ARG_INFO(0, limit)
ZEND_END_ARG_INFO()
#define arginfo_memcache_object_getextendedstats arginfo_memcache_object_getstats
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_setcompressthreshold, 0, 0, 1)
ZEND_ARG_INFO(0, threshold)
ZEND_ARG_INFO(0, min_savings)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_increment, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, defval)
ZEND_ARG_INFO(0, exptime)
ZEND_END_ARG_INFO()
#define arginfo_memcache_object_decrement arginfo_memcache_object_increment
ZEND_BEGIN_ARG_INFO(arginfo_memcache_object_close, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_flush, 0, 0, 0)
ZEND_ARG_INFO(0, delay)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_memcache_object_setSaslAuthData, 0, 0, 2)
ZEND_ARG_INFO(0, username)
ZEND_ARG_INFO(0, password)
ZEND_END_ARG_INFO()
static zend_function_entry php_memcache_pool_class_functions[] = {
PHP_NAMED_FE(connect, zif_memcache_pool_connect, NULL)
PHP_NAMED_FE(addserver, zif_memcache_pool_addserver, NULL)
PHP_FALIAS(setserverparams, memcache_set_server_params, NULL)
PHP_FALIAS(setfailurecallback, memcache_set_failure_callback, NULL)
PHP_FALIAS(getserverstatus, memcache_get_server_status, NULL)
PHP_NAMED_FE(findserver, zif_memcache_pool_findserver, NULL)
PHP_FALIAS(getversion, memcache_get_version, NULL)
PHP_FALIAS(add, memcache_add, NULL)
PHP_FALIAS(set, memcache_set, NULL)
PHP_FALIAS(replace, memcache_replace, NULL)
PHP_FALIAS(cas, memcache_cas, NULL)
PHP_FALIAS(append, memcache_append, NULL)
PHP_FALIAS(prepend, memcache_prepend, NULL)
PHP_NAMED_FE(connect, zif_memcache_pool_connect, arginfo_memcache_object_connect)
PHP_NAMED_FE(addserver, zif_memcache_pool_addserver, arginfo_memcache_object_addserver)
PHP_FALIAS(setserverparams, memcache_set_server_params, arginfo_memcache_object_setserverparams)
PHP_FALIAS(setfailurecallback, memcache_set_failure_callback, arginfo_memcache_object_setfailurecallback)
PHP_FALIAS(getserverstatus, memcache_get_server_status, arginfo_memcache_object_getserverstatus)
PHP_NAMED_FE(findserver, zif_memcache_pool_findserver, arginfo_memcache_object_findserver)
PHP_FALIAS(getversion, memcache_get_version, arginfo_memcache_object_getversion)
PHP_FALIAS(add, memcache_add, arginfo_memcache_object_add)
PHP_FALIAS(set, memcache_set, arginfo_memcache_object_set)
PHP_FALIAS(replace, memcache_replace, arginfo_memcache_object_replace)
PHP_FALIAS(cas, memcache_cas, arginfo_memcache_object_cas)
PHP_FALIAS(append, memcache_append, arginfo_memcache_object_append)
PHP_FALIAS(prepend, memcache_prepend, arginfo_memcache_object_prepend)
PHP_FALIAS(get, memcache_get, arginfo_memcache_object_get)
PHP_FALIAS(delete, memcache_delete, NULL)
PHP_FALIAS(getstats, memcache_get_stats, NULL)
PHP_FALIAS(getextendedstats, memcache_get_extended_stats, NULL)
PHP_FALIAS(setcompressthreshold, memcache_set_compress_threshold, NULL)
PHP_FALIAS(increment, memcache_increment, NULL)
PHP_FALIAS(decrement, memcache_decrement, NULL)
PHP_FALIAS(close, memcache_close, NULL)
PHP_FALIAS(flush, memcache_flush, NULL)
PHP_FALIAS(setSaslAuthData, memcache_set_sasl_auth_data, NULL)
{NULL, NULL, NULL}
PHP_FALIAS(delete, memcache_delete, arginfo_memcache_object_delete)
PHP_FALIAS(getstats, memcache_get_stats, arginfo_memcache_object_getstats)
PHP_FALIAS(getextendedstats, memcache_get_extended_stats, arginfo_memcache_object_getextendedstats)
PHP_FALIAS(setcompressthreshold, memcache_set_compress_threshold, arginfo_memcache_object_setcompressthreshold)
PHP_FALIAS(increment, memcache_increment, arginfo_memcache_object_increment)
PHP_FALIAS(decrement, memcache_decrement, arginfo_memcache_object_decrement)
PHP_FALIAS(close, memcache_close, arginfo_memcache_object_close)
PHP_FALIAS(flush, memcache_flush, arginfo_memcache_object_flush)
PHP_FALIAS(setSaslAuthData, memcache_set_sasl_auth_data, arginfo_memcache_object_setSaslAuthData)
ZEND_FE_END
};
static zend_function_entry php_memcache_class_functions[] = {
PHP_FALIAS(connect, memcache_connect, NULL)
PHP_FALIAS(pconnect, memcache_pconnect, NULL)
PHP_FALIAS(addserver, memcache_add_server, NULL)
{NULL, NULL, NULL}
PHP_ME_MAPPING(connect, memcache_connect, arginfo_memcache_connect, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(pconnect, memcache_pconnect, arginfo_memcache_pconnect, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(addserver, memcache_add_server, arginfo_memcache_object_addserver, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
/* }}} */
@@ -269,7 +464,7 @@ static PHP_INI_MH(OnUpdatePrefixStaticKey) /* {{{ */
if (new_value) {
for (i=0 ; i<ZSTR_LEN(new_value) ; i++) {
if (ZSTR_VAL(new_value)[i]=='.') {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "memcache.session_prefix_static_key cannot have dot inside (.)");
php_error_docref(NULL, E_WARNING, "memcache.session_prefix_static_key cannot have dot inside (.)");
return FAILURE;
}
}
@@ -458,7 +653,7 @@ static char *get_key_prefix() {
*/
PHP_RINIT_FUNCTION(memcache)
{
MEMCACHE_G(session_key_prefix) = get_session_key_prefix(TSRMLS_C);
MEMCACHE_G(session_key_prefix) = get_session_key_prefix();
return SUCCESS;
}
@@ -1018,8 +1213,8 @@ static mmc_t *php_mmc_pool_addserver(
if (pool->protocol == &mmc_binary_protocol) {
zval rv1, rv2;
zval *username = zend_read_property(memcache_ce, mmc_object, "username", strlen("username"), 1, &rv1);
zval *password = zend_read_property(memcache_ce, mmc_object, "password", strlen("password"), 1, &rv2);
zval *username = zend_read_property(memcache_ce, Z_OBJ_P(mmc_object), "username", strlen("username"), 1, &rv1);
zval *password = zend_read_property(memcache_ce, Z_OBJ_P(mmc_object), "password", strlen("password"), 1, &rv2);
if (Z_TYPE_P(username) == IS_STRING && Z_TYPE_P(password) == IS_STRING) {
if (Z_STRLEN_P(username) > 1 && Z_STRLEN_P(password) > 1) {
mmc_request_t *request;
@@ -1058,7 +1253,7 @@ static void php_mmc_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool persistent)
/* initialize pool and object if need be */
if (!mmc_object) {
zend_resource *list_res;
mmc_pool_t *pool = mmc_pool_new();
pool = mmc_pool_new();
pool->failure_callback = (mmc_failure_callback) &php_mmc_failure_callback;
list_res = zend_register_resource(pool, le_memcache_pool);
mmc_object = return_value;
@@ -1241,7 +1436,7 @@ static void php_mmc_failure_callback(mmc_pool_t *pool, mmc_t *mmc, zval *param)
}
ZVAL_LONG(errnum, mmc->errnum);
call_user_function_ex(EG(function_table), NULL, callback, &retval, 5, params, 0, NULL);
call_user_function(EG(function_table), NULL, callback, &retval, 5, params);
zval_ptr_dtor(host);
zval_ptr_dtor(tcp_port); zval_ptr_dtor(udp_port);
@@ -1252,7 +1447,7 @@ static void php_mmc_failure_callback(mmc_pool_t *pool, mmc_t *mmc, zval *param)
}
}
else {
php_mmc_set_failure_callback(pool, (zval *)param, NULL);
php_mmc_set_failure_callback(pool, param, NULL);
php_error_docref(NULL, E_WARNING, "Invalid failure callback");
}
}
@@ -1754,6 +1949,9 @@ int mmc_value_handler_multi(
if (Z_TYPE_P(result[0]) != IS_ARRAY) {
array_init(result[0]);
}
ZEND_ASSERT(key_len > 0);
add_assoc_zval_ex(result[0], (char *)key, key_len, value);
/* add flags to result */
@@ -2241,8 +2439,8 @@ PHP_FUNCTION(memcache_set_sasl_auth_data)
if (user_length < 1 || password_length < 1) {
RETURN_FALSE;
}
zend_update_property_stringl(memcache_pool_ce, mmc_object, "username", strlen("username"), user, user_length);
zend_update_property_stringl(memcache_pool_ce, mmc_object, "password", strlen("password"), password, password_length);
zend_update_property_stringl(memcache_pool_ce, Z_OBJ_P(mmc_object), "username", strlen("username"), user, user_length);
zend_update_property_stringl(memcache_pool_ce, Z_OBJ_P(mmc_object), "password", strlen("password"), password, password_length);
RETURN_TRUE;
}
/* }}} */

View File

@@ -129,7 +129,7 @@ static int mmc_request_parse_mutate(mmc_t *mmc, mmc_request_t *request) /*
return request->response_handler(mmc, request, response, line, line_len - (sizeof("\r\n")-1), request->response_handler_param);
}
if (sscanf(line, "%lu", &lval) < 1) {
if (sscanf(line, "%ld", &lval) < 1) {
return mmc_server_failure(mmc, request->io, "Malformed VALUE header", 0);
}

View File

@@ -733,7 +733,16 @@ static int mmc_server_connect(mmc_pool_t *pool, mmc_t *mmc, mmc_stream_t *io, in
/* check connection and extract socket for select() purposes */
if (!io->stream || php_stream_cast(io->stream, PHP_STREAM_AS_FD_FOR_SELECT, (void **)&fd, 1) != SUCCESS) {
mmc_server_seterror(mmc, errstr != NULL ? ZSTR_VAL(errstr) : "Connection failed", errnum);
if (errstr != NULL) {
zend_string* error = zend_string_concat2(
"Connection failed: ", sizeof("Connection failed: ") - 1,
ZSTR_VAL(errstr), ZSTR_LEN(errstr));
mmc_server_seterror(mmc, ZSTR_VAL(error), errnum);
zend_string_release(error);
} else {
mmc_server_seterror(mmc, "Connection failed", errnum);
}
mmc_server_deactivate(pool, mmc);
if (errstr != NULL) {
@@ -821,6 +830,8 @@ void mmc_server_sleep(mmc_t *mmc) /*
void mmc_server_free(mmc_t *mmc) /* {{{ */
{
mmc_server_sleep(mmc);
pefree(mmc->host, mmc->persistent);
pefree(mmc, mmc->persistent);
}

View File

@@ -64,12 +64,13 @@ PS_OPEN_FUNC(memcache)
}
if (!path) {
PS_SET_MOD_DATA(NULL);
ZEND_ASSERT(0 && "open");
return FAILURE;
}
pool = mmc_pool_new();
for (i=0,j=0,path_len=strlen(path); i<path_len; i=j+1) {
for (i=0,path_len=strlen(path); i<path_len; i=j+1) {
/* find beginning of url */
while (i<path_len && (isspace(path[i]) || path[i] == ',')) {
i++;
@@ -205,6 +206,7 @@ PS_OPEN_FUNC(memcache)
mmc_pool_free(pool);
PS_SET_MOD_DATA(NULL);
ZEND_ASSERT(0 &&"open");
return FAILURE;
}
/* }}} */
@@ -417,6 +419,9 @@ PS_WRITE_FUNC(memcache)
if (mmc_prepare_key_ex(ZSTR_VAL(key), ZSTR_LEN(key), datarequest->key, &(datarequest->key_len), MEMCACHE_G(session_key_prefix)) != MMC_OK) {
mmc_pool_release(pool, datarequest);
if (lockrequest != NULL) {
mmc_pool_release(pool, lockrequest);
}
break;
}
@@ -450,6 +455,7 @@ PS_WRITE_FUNC(memcache)
mmc_pool_schedule(pool, mmc, lockrequest) != MMC_OK) {
mmc_pool_release(pool, datarequest);
mmc_pool_release(pool, lockrequest);
lockrequest = NULL;
continue;
}
} while (skip_servers.len < MEMCACHE_G(session_redundancy) && skip_servers.len < pool->num_servers);

View File

@@ -19,8 +19,17 @@ memcache_set($memcache, $key, $value, false, 10);
var_dump($key);
var_dump($value);
memcache_set($memcache, $key);
$memcache->set($key);
try {
memcache_set($memcache, $key);
} catch (ArgumentCountError $e) {
echo "{$e->getMessage()}\n";
}
try {
$memcache->set($key);
} catch (ArgumentCountError $e) {
echo "{$e->getMessage()}\n";
}
echo "Done\n";
@@ -28,8 +37,6 @@ echo "Done\n";
--EXPECTF--
int(123)
int(123)
Warning: %s parameter%s
Warning: %s parameter%s
Wrong parameter count for memcache_set()
Wrong parameter count for MemcachePool::set()
Done

View File

@@ -9,8 +9,18 @@ include 'connect.inc';
var_dump(memcache_add_server($memcache, $host2, $port2));
var_dump(memcache_add_server($memcache, $nonExistingHost, $nonExistingPort));
var_dump(memcache_add_server(new stdclass, $host2, $port2));
var_dump(memcache_add_server($memcache, new stdclass, array()));
try {
var_dump(memcache_add_server(new stdclass, $host2, $port2));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
try {
var_dump(memcache_add_server($memcache, new stdclass, array()));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
echo "Done\n";
@@ -18,10 +28,6 @@ echo "Done\n";
--EXPECTF--
bool(true)
bool(true)
Warning: memcache_add_server() expects parameter 1 to be Memcache, object given in %s on line %d
NULL
Warning: memcache_add_server() expects parameter 2 to be string, object given in %s on line %d
NULL
memcache_add_server(): Argument #1 ($memcache) must be of type Memcache, stdClass given
memcache_add_server(): Argument #2 ($host) must be of type string, stdClass given
Done

View File

@@ -14,8 +14,16 @@ memcache_add_server($memcache, $host2, $port2);
$result1 = @memcache_get_stats($memcache);
$result2 = @memcache_get_extended_stats($memcache);
var_dump(memcache_get_extended_stats(array()));
var_dump(memcache_get_extended_stats(new stdClass));
try {
var_dump(memcache_get_extended_stats(array()));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
try {
var_dump(memcache_get_extended_stats(new stdClass));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
var_dump($result1['pid']);
@@ -26,11 +34,8 @@ var_dump($result2["$nonExistingHost:$nonExistingPort"]);
?>
--EXPECTF--
Warning: memcache_get_extended_stats() expects parameter 1 to be MemcachePool, array given in %s on line %d
NULL
Warning: memcache_get_extended_stats() expects parameter 1 to be MemcachePool, object given in %s on line %d
NULL
memcache_get_extended_stats(): Argument #1 ($memcache) must be of type MemcachePool, array given
memcache_get_extended_stats(): Argument #1 ($memcache) must be of type MemcachePool, stdClass given
string(%d) "%d"
int(3)
string(%d) "%d"

View File

@@ -29,8 +29,16 @@ var_dump($result5);
var_dump(memcache_close($memcache));
var_dump(memcache_close($memcache));
var_dump(memcache_close(new stdClass));
var_dump(memcache_close(""));
try {
var_dump(memcache_close(new stdClass));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
try {
var_dump(memcache_close(""));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
echo "Done\n";
@@ -43,10 +51,6 @@ bool(true)
bool(false)
bool(true)
bool(true)
Warning: memcache_close() expects parameter 1 to be MemcachePool, object given in %s on line %d
NULL
Warning: memcache_close() expects parameter 1 to be MemcachePool, string given in %s on line %d
NULL
memcache_close(): Argument #1 ($memcache) must be of type MemcachePool, stdClass given
memcache_close(): Argument #1 ($memcache) must be of type MemcachePool, string given
Done

View File

@@ -30,12 +30,19 @@ $result6 = memcache_get($memcache, 'non_existing_test_key');
var_dump($result5);
var_dump($result6);
var_dump(memcache_set_compress_threshold(array(), 10000, 0));
try {
var_dump(memcache_set_compress_threshold(array(), 10000, 0));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
var_dump(memcache_set_compress_threshold($memcache, -1, -1));
var_dump(memcache_set_compress_threshold($memcache, 1, -1));
var_dump(memcache_set_compress_threshold($memcache, -1, 1));
var_dump(memcache_set_compress_threshold(new stdClass, 1, 1));
try {
var_dump(memcache_set_compress_threshold(new stdClass, 1, 1));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
echo "Done\n";
@@ -47,9 +54,7 @@ bool(true)
bool(true)
bool(true)
string(3) "abc"
Warning: memcache_set_compress_threshold() expects parameter 1 to be MemcachePool, array given in %s on line %d
NULL
memcache_set_compress_threshold(): Argument #1 ($memcache) must be of type MemcachePool, array given
Warning: memcache_set_compress_threshold()%s threshold must be a positive integer in %s on line %d
bool(false)
@@ -59,7 +64,5 @@ bool(false)
Warning: memcache_set_compress_threshold()%s threshold must be a positive integer in %s on line %d
bool(false)
Warning: memcache_set_compress_threshold() expects parameter 1 to be MemcachePool, object given in %s on line %d
NULL
memcache_set_compress_threshold(): Argument #1 ($memcache) must be of type MemcachePool, stdClass given
Done

View File

@@ -12,6 +12,7 @@ $memcache->set($balanceKey1, 1, 0, 10);
$memcache->set($balanceKey2, 2, 0, 10);
$result = $memcache->increment(array($balanceKey1, $balanceKey2), 1);
asort($result);
var_dump($result);
$result1 = $memcache->get($balanceKey1);
@@ -20,18 +21,22 @@ var_dump($result1);
var_dump($result2);
$result = $memcache->decrement(array($balanceKey1, $balanceKey2), 1);
asort($result);
var_dump($result);
$result = memcache_increment($memcache, array($balanceKey1, $balanceKey2), 1);
asort($result);
var_dump($result);
$result = memcache_decrement($memcache, array($balanceKey1, $balanceKey2), 1);
asort($result);
var_dump($result);
$result = $memcache->increment(array());
var_dump($result);
$result = $memcache->increment(array('unset_test_key', 'unset_test_key1'));
asort($result);
var_dump($result);
?>

View File

@@ -3,12 +3,7 @@ ini_set('memcache.session_redundancy')
--SKIPIF--
<?php
include 'connect.inc';
include 'version.inc';
if (defined('PHP_VERSION_ID') && !(PHP_VERSION_ID < 70300)) {
die("skip");
}
?>
--FILE--
<?php
ob_start();
@@ -23,7 +18,9 @@ ini_set('memcache.session_save_path', "tcp://$host:$port?udp_port=$udpPort, tcp:
$memcache1 = test_connect1();
$memcache2 = test_connect2();
$memcache1->delete($balanceKey1);
$memcache1->delete($balanceKey2);
$memcache2->delete($balanceKey1);
$memcache2->delete($balanceKey2);
// Test set
session_id($balanceKey1);
@@ -38,7 +35,7 @@ var_dump($result2);
// Test delete
session_id($balanceKey1);
@session_start();
session_start();
session_destroy();
$result1 = $memcache1->get($balanceKey1);
@@ -48,7 +45,7 @@ var_dump($result2);
// Test lost session on server1
session_id($balanceKey1);
@session_start();
session_start();
$_SESSION['key'] = 'Test2';
session_write_close();
unset($_SESSION['key']);
@@ -63,7 +60,7 @@ session_write_close();
// Test lost session on server2
session_id($balanceKey2);
@session_start();
session_start();
$_SESSION['key'] = 'Test3';
session_write_close();
unset($_SESSION['key']);
@@ -72,7 +69,7 @@ $result = $memcache2->delete($balanceKey1);
var_dump($result);
session_id($balanceKey2);
@session_start();
session_start();
var_dump($_SESSION);
session_write_close();
ob_flush();

View File

@@ -3,11 +3,6 @@ ini_set('memcache.session_redundancy')
--SKIPIF--
<?php
include 'connect.inc';
include 'version.inc';
print(PHP_VERSION_ID);
if (defined('PHP_VERSION_ID') && (PHP_VERSION_ID > 70200)) {
die("skip");
}
?>
--FILE--

View File

@@ -27,8 +27,16 @@ var_dump($result);
memcache_close($memcache);
var_dump(memcache_flush($memcache));
var_dump(memcache_flush(new stdClass));
var_dump(memcache_flush(''));
try {
var_dump(memcache_flush(new stdClass));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
try {
var_dump(memcache_flush(''));
} catch (TypeError $e) {
echo "{$e->getMessage()}\n";
}
echo "Done\n";
@@ -38,10 +46,6 @@ bool(true)
bool(false)
bool(false)
bool(true)
Warning: memcache_flush() expects parameter 1 to be MemcachePool, object given in %s on line %d
NULL
Warning: memcache_flush() expects parameter 1 to be MemcachePool, string given in %s on line %d
NULL
memcache_flush(): Argument #1 ($memcache) must be of type MemcachePool, stdClass given
memcache_flush(): Argument #1 ($memcache) must be of type MemcachePool, string given
Done

View File

@@ -2,11 +2,7 @@
memcache multi host save path function
--SKIPIF--
<?php
include 'connect.inc';
if (defined('PHP_VERSION_ID') && PHP_VERSION_ID > 70000) {
die("skip not relevant for php 7.1+
");
}
include 'connect.inc';
?>
--FILE--
<?php
@@ -17,7 +13,12 @@ $session_save_path = "tcp://$host:$port,tcp://$host2:$port2";
ini_set('session.save_handler', 'memcache');
ini_set('memcache.session_save_path', $session_save_path);
session_id('abcdef');
session_start();
$_SESSION['bof.test'] = 42;
session_write_close();
$_SESSION = array();
function test() {
session_name('SID_bof');
@@ -31,6 +32,11 @@ function test() {
session_write_close();
}
ini_set('memcache.session_save_path', "tcp://$host:$port");
test();
ini_set('memcache.session_save_path', "tcp://$host2:$port2");
test();
ini_set('memcache.session_save_path', "tcp://$host:$port, tcp://$host2:$port2");
test();
echo "Done\n";
@@ -38,16 +44,15 @@ ob_flush();
?>
--EXPECTF--
array(1) {
'bof.test' =>
["bof.test"]=>
int(42)
}
array(1) {
'bof.test' =>
["bof.test"]=>
int(42)
}
array(1) {
'bof.test' =>
["bof.test"]=>
int(42)
}
Done

View File

@@ -1,7 +1,7 @@
<?php
if (!extension_loaded("memcache")) {
die("skip");
die("skip memcache module not loaded");
}
error_reporting(E_ALL);
@@ -93,5 +93,3 @@ function test_connect_pool() {
if (!$memcache) {
die('skip Connection to memcached failed');
}
?>