Skip to content

Restore libmemcached compat #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ if test "$PHP_MEMCACHED" != "no"; then
AC_DEFINE(HAVE_MEMCACHED_EXIST, [1], [Whether memcached_exist is defined])
fi

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

if test "$PHP_SYSTEM_FASTLZ" != "no"; then
AC_CHECK_HEADERS([fastlz.h], [ac_cv_have_fastlz="yes"], [ac_cv_have_fastlz="no"])
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Tests
<file role='src' name='php_memcached_private.h'/>
<file role='src' name='php_memcached_session.c'/>
<file role='src' name='php_memcached_session.h'/>
<file role='src' name='php_libmemcached_compat.h'/>
<file role='src' name='php_libmemcached_compat.c'/>
<file role='src' name='php_memcached_server.h'/>
<file role='src' name='php_memcached_server.c'/>
<file role='src' name='g_fmt.c'/>
Expand Down
37 changes: 37 additions & 0 deletions php_libmemcached_compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andrei Zmievski <[email protected]> |
+----------------------------------------------------------------------+
*/

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

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

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

#ifndef PHP_LIBMEMCACHED_COMPAT
#define PHP_LIBMEMCACHED_COMPAT

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

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

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

#endif
2 changes: 0 additions & 2 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -4022,7 +4022,6 @@ static zend_function_entry memcached_class_methods[] = {
MEMC_ME(getLastErrorMessage, arginfo_getLastErrorMessage)
MEMC_ME(getLastErrorCode, arginfo_getLastErrorCode)
MEMC_ME(getLastErrorErrno, arginfo_getLastErrorErrno)

MEMC_ME(getLastDisconnectedServer, arginfo_getLastDisconnectedServer)

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

REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_COMPATIBLE, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_HASH, MEMCACHED_BEHAVIOR_KETAMA_HASH);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_TCP_KEEPALIVE, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE);
Expand Down
10 changes: 3 additions & 7 deletions php_memcached_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@
# include "config.h"
#endif

#include <libmemcached/memcached.h>

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

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

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

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

zend_bool php_memc_init_sasl_if_needed();

#endif /* PHP_MEMCACHED_PRIVATE_H */
Expand Down
2 changes: 1 addition & 1 deletion php_memcached_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ PS_VALIDATE_SID_FUNC(memcached)
{
memcached_st *memc = PS_GET_MOD_DATA();

if (memcached_exist(memc, key->val, key->len) == MEMCACHED_SUCCESS) {
if (php_memcached_exist(memc, key) == MEMCACHED_SUCCESS) {
return SUCCESS;
} else {
return FAILURE;
Expand Down