Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed getServerByKey function #42

Merged
merged 3 commits into from

2 participants

@poison

The underlying function memcached_server_by_key returns a memcached_server_instance_st instead of memcached_server_st. The structures were compatible to each other, but this
recently changed between 1.0.5 and 1.0.13. This made this function failing.

See https://bugs.launchpad.net/libmemcached/+bug/1076048 for more info.

By using the proper function calls they work again, but unfortunately there's no fix for the weight. I think it's useless to return the weight, since you can know it from php-user-land (it's passed to either addServer or addServers). I suggest to remove the weight as a return type, but I didn't want to break anyone's code.

poison added some commits
@poison poison memcached_server_by_key actually returns a memcached_server_instance_…
…st instead

of memcached_server_st. The structures were compatible to eachother, but this
recently changed between 1.0.5 and 1.0.13.

See https://bugs.launchpad.net/libmemcached/+bug/1076048 for more info.
5450f45
@poison poison Added 4 functions to further debug issues and error codes in a multi-…
…server environment:

	getLastErrorMessage()
	getLastErrorCode()
	getLastErrorErrno()
	getLastDisconnectedServer()
d9a2e8b
@poison poison Added MEMCACHED_BEHAVIOR_DEAD_TIMEOUT class constant 'OPT_DEAD_TIMEOU…
…T' (new in 1.0.3)
30d9031
@iliaal iliaal merged commit bf4f978 into php-memcached-dev:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 10, 2012
  1. @poison

    memcached_server_by_key actually returns a memcached_server_instance_…

    poison authored
    …st instead
    
    of memcached_server_st. The structures were compatible to eachother, but this
    recently changed between 1.0.5 and 1.0.13.
    
    See https://bugs.launchpad.net/libmemcached/+bug/1076048 for more info.
Commits on Nov 12, 2012
  1. @poison

    Added 4 functions to further debug issues and error codes in a multi-…

    poison authored
    …server environment:
    
    	getLastErrorMessage()
    	getLastErrorCode()
    	getLastErrorErrno()
    	getLastDisconnectedServer()
Commits on Nov 14, 2012
  1. @poison
This page is out of date. Refresh to see the latest.
Showing with 114 additions and 7 deletions.
  1. +10 −0 memcached-api.php
  2. +104 −7 php_memcached.c
View
10 memcached-api.php
@@ -53,6 +53,8 @@ class Memcached {
const OPT_RETRY_TIMEOUT;
+ const OPT_DEAD_TIMEOUT;
+
const OPT_SND_TIMEOUT;
const OPT_RCV_TIMEOUT;
@@ -257,6 +259,14 @@ public function getServerList( ) {}
public function getServerByKey( $server_key ) {}
+ public function getLastErrorMessage( ) {}
+
+ public function getLastErrorCode( ) {}
+
+ public function getLastErrorErrno( ) {}
+
+ public function getLastDisconnectedServer( ) {}
+
public function flush( $delay = 0 ) {}
public function getStats( ) {}
View
111 php_memcached.c
@@ -1965,7 +1965,7 @@ PHP_METHOD(Memcached, getServerByKey)
{
char *server_key;
int server_key_len;
- memcached_server_st *server;
+ memcached_server_instance_st *server_instance;
memcached_return error;
MEMC_METHOD_INIT_VARS;
@@ -1981,16 +1981,16 @@ PHP_METHOD(Memcached, getServerByKey)
RETURN_FALSE;
}
- server = memcached_server_by_key(m_obj->memc, server_key, server_key_len, &error);
- if (server == NULL) {
+ server_instance = memcached_server_by_key(m_obj->memc, server_key, server_key_len, &error);
+ if (server_instance == NULL) {
php_memc_handle_error(i_obj, error TSRMLS_CC);
RETURN_FALSE;
}
array_init(return_value);
- add_assoc_string(return_value, "host", server->hostname, 1);
- add_assoc_long(return_value, "port", server->port);
- add_assoc_long(return_value, "weight", server->weight);
+ add_assoc_string(return_value, "host", (char*) memcached_server_name(server_instance), 1);
+ add_assoc_long(return_value, "port", memcached_server_port(server_instance));
+ add_assoc_long(return_value, "weight", 0);
}
/* }}} */
@@ -2028,6 +2028,81 @@ PHP_METHOD(Memcached, quit)
}
/* }}} */
+#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
+/* {{{ Memcached::getLastErrorMessage()
+ Returns the last error message that occurred */
+PHP_METHOD(Memcached, getLastErrorMessage)
+{
+ MEMC_METHOD_INIT_VARS;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ MEMC_METHOD_FETCH_OBJECT;
+
+ RETURN_STRING(memcached_last_error_message(m_obj->memc), 1);
+}
+/* }}} */
+
+/* {{{ Memcached::getLastErrorCode()
+ Returns the last error code that occurred */
+PHP_METHOD(Memcached, getLastErrorCode)
+{
+ MEMC_METHOD_INIT_VARS;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ MEMC_METHOD_FETCH_OBJECT;
+
+ RETURN_LONG(memcached_last_error(m_obj->memc));
+}
+/* }}} */
+
+/* {{{ Memcached::getLastErrorErrno()
+ Returns the last error errno that occurred */
+PHP_METHOD(Memcached, getLastErrorErrno)
+{
+ MEMC_METHOD_INIT_VARS;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ MEMC_METHOD_FETCH_OBJECT;
+
+ RETURN_LONG(memcached_last_error_errno(m_obj->memc));
+}
+/* }}} */
+#endif
+
+/* {{{ Memcached::getLastDisconnectedServer()
+ Returns the last disconnected server
+ Was added in 0.34 according to libmemcached's Changelog */
+PHP_METHOD(Memcached, getLastDisconnectedServer)
+{
+ memcached_server_instance_st *server_instance;
+ MEMC_METHOD_INIT_VARS;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ MEMC_METHOD_FETCH_OBJECT;
+
+ server_instance = memcached_server_get_last_disconnect(m_obj->memc);
+ if (server_instance == NULL) {
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+ add_assoc_string(return_value, "host", (char*) memcached_server_name(server_instance), 1);
+ add_assoc_long(return_value, "port", memcached_server_port(server_instance));
+}
+/* }}} */
+
/* {{{ Memcached::getStats()
Returns statistics for the memcache servers */
PHP_METHOD(Memcached, getStats)
@@ -2587,7 +2662,7 @@ static memcached_return php_memc_do_serverlist_callback(const memcached_st *ptr,
MAKE_STD_ZVAL(array);
array_init(array);
- add_assoc_string(array, "host", memcached_server_name(instance), 1);
+ add_assoc_string(array, "host", (char*) memcached_server_name(instance), 1);
add_assoc_long(array, "port", memcached_server_port(instance));
/*
* API does not allow to get at this field.
@@ -3486,6 +3561,18 @@ ZEND_BEGIN_ARG_INFO(arginfo_getServerByKey, 0)
ZEND_ARG_INFO(0, server_key)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(arginfo_getLastErrorMessage, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_getLastErrorCode, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_getLastErrorErrno, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_getLastDisconnectedServer, 0)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO(arginfo_getOption, 0)
ZEND_ARG_INFO(0, option)
ZEND_END_ARG_INFO()
@@ -3573,6 +3660,13 @@ static zend_function_entry memcached_class_methods[] = {
MEMC_ME(resetServerList, arginfo_resetServerList)
MEMC_ME(quit, arginfo_quit)
+#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
+ MEMC_ME(getLastErrorMessage, arginfo_getLastErrorMessage)
+ MEMC_ME(getLastErrorCode, arginfo_getLastErrorCode)
+ MEMC_ME(getLastErrorErrno, arginfo_getLastErrorErrno)
+#endif
+ MEMC_ME(getLastDisconnectedServer, arginfo_getLastDisconnectedServer)
+
MEMC_ME(getStats, arginfo_getStats)
MEMC_ME(getVersion, arginfo_getVersion)
MEMC_ME(getAllKeys, arginfo_getAllKeys)
@@ -3711,6 +3805,9 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
REGISTER_MEMC_CLASS_CONST_LONG(OPT_SOCKET_RECV_SIZE, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_CONNECT_TIMEOUT, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_RETRY_TIMEOUT, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT);
+#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000003
+ REGISTER_MEMC_CLASS_CONST_LONG(OPT_DEAD_TIMEOUT, MEMCACHED_BEHAVIOR_DEAD_TIMEOUT);
+#endif
REGISTER_MEMC_CLASS_CONST_LONG(OPT_SEND_TIMEOUT, MEMCACHED_BEHAVIOR_SND_TIMEOUT);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_RECV_TIMEOUT, MEMCACHED_BEHAVIOR_RCV_TIMEOUT);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_POLL_TIMEOUT, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
Something went wrong with that request. Please try again.