mirror of
https://github.com/php-win-ext/php-memcached.git
synced 2026-03-24 00:52:18 +01:00
implement stats callback suggestions by Remi
This commit is contained in:
@@ -519,7 +519,7 @@ protocol_binary_response_status s_stat_handler (const void *cookie, const void *
|
||||
} else {
|
||||
ZVAL_NULL(&zkey);
|
||||
}
|
||||
ZVAL_NULL(&zstats);
|
||||
array_init(&zstats);
|
||||
ZVAL_MAKE_REF(&zstats);
|
||||
|
||||
ZVAL_COPY(¶ms[0], &zcookie);
|
||||
@@ -529,29 +529,34 @@ protocol_binary_response_status s_stat_handler (const void *cookie, const void *
|
||||
retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_STAT), params, 3);
|
||||
|
||||
if (retval == PROTOCOL_BINARY_RESPONSE_SUCCESS) {
|
||||
if (Z_ISNULL(zstats)) {
|
||||
retval = response_handler(cookie, NULL, 0, NULL, 0);
|
||||
} else {
|
||||
zval *zarray = &zstats;
|
||||
zend_string *key;
|
||||
zval *val;
|
||||
zval *zarray = &zstats;
|
||||
zend_string *key;
|
||||
zend_long idx;
|
||||
zval *val;
|
||||
|
||||
ZVAL_DEREF(zarray);
|
||||
if (Z_TYPE_P(zarray) != IS_ARRAY) {
|
||||
convert_to_array(zarray);
|
||||
}
|
||||
|
||||
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zarray), key, val)
|
||||
{
|
||||
zend_string *val_str = zval_get_string(val);
|
||||
retval = response_handler(cookie, key->val, key->len, val_str->val, val_str->len);
|
||||
if (retval != PROTOCOL_BINARY_RESPONSE_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
zend_string_release(val_str);
|
||||
}
|
||||
ZEND_HASH_FOREACH_END();
|
||||
ZVAL_DEREF(zarray);
|
||||
if (Z_TYPE_P(zarray) != IS_ARRAY) {
|
||||
convert_to_array(zarray);
|
||||
}
|
||||
|
||||
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(zarray), idx, key, val)
|
||||
{
|
||||
zend_string *val_str = zval_get_string(val);
|
||||
|
||||
if (key) {
|
||||
retval = response_handler(cookie, key->val, key->len, val_str->val, val_str->len);
|
||||
} else {
|
||||
char buf[0x20], *ptr, *end = &buf[sizeof(buf) - 1];
|
||||
ptr = zend_print_long_to_buf(end, idx);
|
||||
retval = response_handler(cookie, ptr, end - ptr, val_str->val, val_str->len);
|
||||
}
|
||||
zend_string_release(val_str);
|
||||
|
||||
if (retval != PROTOCOL_BINARY_RESPONSE_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ZEND_HASH_FOREACH_END();
|
||||
}
|
||||
|
||||
zval_ptr_dtor(¶ms[0]);
|
||||
|
||||
@@ -37,6 +37,8 @@ $cache->replace ('replace_key', 'value 2', 200);
|
||||
var_dump($cache->getVersion());
|
||||
var_dump($cache->getStats());
|
||||
var_dump($cache->getStats("foobar"));
|
||||
var_dump($cache->getStats("scalar"));
|
||||
var_dump($cache->getStats("numeric array"));
|
||||
|
||||
$cache->quit();
|
||||
|
||||
@@ -84,5 +86,25 @@ array(1) {
|
||||
string(3) "bar"
|
||||
}
|
||||
}
|
||||
client_id=[%s]: Stat key=[scalar]
|
||||
array(1) {
|
||||
["127.0.0.1:3434"]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(%d) "you want it, you get it"
|
||||
}
|
||||
}
|
||||
client_id=[%s]: Stat key=[numeric array]
|
||||
array(1) {
|
||||
["127.0.0.1:3434"]=>
|
||||
array(3) {
|
||||
[-1]=>
|
||||
string(3) "one"
|
||||
[0]=>
|
||||
string(3) "two"
|
||||
[1]=>
|
||||
string(5) "three"
|
||||
}
|
||||
}
|
||||
client_id=[%s]: Client quit
|
||||
Done
|
||||
|
||||
@@ -77,13 +77,18 @@ $server->on (Memcached::ON_SET,
|
||||
});
|
||||
|
||||
$server->on (Memcached::ON_STAT,
|
||||
function ($client_id, $key, array &$values = null) {
|
||||
echo "client_id=[$client_id]: Stat key=[$key]" . PHP_EOL;
|
||||
$values = [
|
||||
"key" => $key,
|
||||
"foo" => "bar",
|
||||
];
|
||||
return Memcached::RESPONSE_SUCCESS;
|
||||
function ($client_id, $key, array &$values) {
|
||||
echo "client_id=[$client_id]: Stat key=[$key]" . PHP_EOL;
|
||||
|
||||
if ($key === "scalar") {
|
||||
$values = "you want it, you get it";
|
||||
} elseif ($key === "numeric array") {
|
||||
$values = [-1 => "one", "two", "three"];
|
||||
} else {
|
||||
$values["key"] = $key;
|
||||
$values["foo"] = "bar";
|
||||
}
|
||||
return Memcached::RESPONSE_SUCCESS;
|
||||
});
|
||||
|
||||
$server->on (Memcached::ON_VERSION,
|
||||
|
||||
Reference in New Issue
Block a user