From e65e4aef04bbda60b8fb12985afbfaa069de9aee Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 31 Jan 2007 12:14:07 +0000 Subject: [PATCH] - use a HashTable to stat persistent handles - show p. handles with phpinfo --- http.c | 29 +++++++++++++++++++++++++++++ http_functions.c | 16 ++++------------ http_persistent_handle_api.c | 31 +++++++++++++++++-------------- php_http_persistent_handle_api.h | 6 +++--- 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/http.c b/http.c index fc7f15a..f0ffeae 100644 --- a/http.c +++ b/http.c @@ -433,6 +433,35 @@ PHP_MINFO_FUNCTION(http) "http.chunked_decode, http.chunked_encode, http.deflate, http.inflate" #endif ); +#ifdef HTTP_HAVE_PERSISTENT_HANDLES + { + phpstr s; + HashTable *ht; + HashPosition pos; + HashKey key = initHashKey(0); + zval **val; + + if ((ht = http_persistent_handle_statall())) { + phpstr_init(&s); + + FOREACH_HASH_KEYVAL(pos, ht, key, val) { + phpstr_appendf(&s, "%s (%d), ", key.str, Z_LVAL_PP(val)); + } + zend_hash_destroy(ht); + FREE_HASHTABLE(ht); + + PHPSTR_LEN(&s) -= 2; /* get rid of last ", " */ + phpstr_fix(&s); + + php_info_print_table_row(2, "Persistent Handles", PHPSTR_VAL(&s)); + phpstr_dtor(&s); + } else { + php_info_print_table_row(2, "Persistent Handles", "none"); + } + } +#else + php_info_print_table_row(2, "Persistent Handles", "disabled"); +#endif } php_info_print_table_end(); diff --git a/http_functions.c b/http_functions.c index 8941a93..511230e 100644 --- a/http_functions.c +++ b/http_functions.c @@ -809,20 +809,12 @@ PHP_FUNCTION(http_match_request_header) /* {{{ proto object http_persistent_handles_count() */ PHP_FUNCTION(http_persistent_handles_count) { - char **names; - int *counts; - int i, n; - NO_ARGS; - if ((n = http_persistent_handle_statall(&names, &counts))) { - object_init(return_value); - for (i = 0; i < n; ++i) { - add_property_long(return_value, names[i], counts[i]); - efree(names[i]); - } - efree(names); - efree(counts); + object_init(return_value); + if (!http_persistent_handle_statall_ex(HASH_OF(return_value))) { + zval_dtor(return_value); + RETURN_NULL(); } } /* }}} */ diff --git a/http_persistent_handle_api.c b/http_persistent_handle_api.c index 159d378..c89c539 100644 --- a/http_persistent_handle_api.c +++ b/http_persistent_handle_api.c @@ -13,9 +13,9 @@ /* $Id$ */ #include "php_http.h" +#include "php_http_api.h" #ifdef HTTP_HAVE_PERSISTENT_HANDLES - #include "php_http_persistent_handle_api.h" static HashTable http_persistent_handles_hash; @@ -114,28 +114,31 @@ PHP_HTTP_API void _http_persistent_handle_cleanup_ex(const char *name_str, size_ UNLOCK(); } -PHP_HTTP_API int _http_persistent_handle_statall_ex(char ***names, int **counts, int persistent) +PHP_HTTP_API HashTable *_http_persistent_handle_statall_ex(HashTable *ht) { - int i, n; - char *key; + zval *tmp; + HashPosition pos; + HashKey key = initHashKey(0); http_persistent_handles_hash_entry *hentry; LOCK(); - if ((n = zend_hash_num_elements(&http_persistent_handles_hash))) { - *names = safe_pemalloc(n, sizeof(char **), 0, persistent); - *counts = safe_pemalloc(n, sizeof(int), 0, persistent); + if (zend_hash_num_elements(&http_persistent_handles_hash)) { + if (!ht) { + ALLOC_HASHTABLE(ht); + zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0); + } - for ( i = 0, zend_hash_internal_pointer_reset(&http_persistent_handles_hash); - HASH_KEY_NON_EXISTANT != zend_hash_get_current_key(&http_persistent_handles_hash, &key, NULL, 0) && - SUCCESS == zend_hash_get_current_data(&http_persistent_handles_hash, (void *) &hentry); - ++i, zend_hash_move_forward(&http_persistent_handles_hash)) { - (*names)[i] = pestrdup(key, persistent); - (*counts)[i] = zend_hash_num_elements(&hentry->list); + FOREACH_HASH_KEYVAL(pos, &http_persistent_handles_hash, key, hentry) { + MAKE_STD_ZVAL(tmp); + ZVAL_LONG(tmp, zend_hash_num_elements(&hentry->list)); + zend_hash_add(ht, key.str, key.len, (void *) &tmp, sizeof(zval *), NULL); } + } else if (ht) { + ht = NULL; } UNLOCK(); - return n; + return ht; } PHP_HTTP_API STATUS _http_persistent_handle_acquire_ex(const char *name_str, size_t name_len, void **handle) diff --git a/php_http_persistent_handle_api.h b/php_http_persistent_handle_api.h index 661c8e1..27d640f 100644 --- a/php_http_persistent_handle_api.h +++ b/php_http_persistent_handle_api.h @@ -30,9 +30,9 @@ PHP_HTTP_API STATUS _http_persistent_handle_provide_ex(const char *name_str, siz #define http_persistent_handle_cleanup_ex(n, l) _http_persistent_handle_cleanup_ex((n), (l)) PHP_HTTP_API void _http_persistent_handle_cleanup_ex(const char *name_str, size_t name_len); -#define http_persistent_handle_statall(n, c) _http_persistent_handle_statall_ex((n), (c), 0) -#define http_persistent_handle_statall_ex(n, c, p) _http_persistent_handle_statall_ex((n), (c), (p)) -PHP_HTTP_API int _http_persistent_handle_statall_ex(char ***names, int **counts, int persistent); +#define http_persistent_handle_statall() _http_persistent_handle_statall_ex(NULL) +#define http_persistent_handle_statall_ex(ht) _http_persistent_handle_statall_ex((ht)) +PHP_HTTP_API HashTable *_http_persistent_handle_statall_ex(HashTable *ht); #define http_persistent_handle_acquire(n, h) _http_persistent_handle_acquire_ex((n), strlen(n), (h)) #define http_persistent_handle_acquire_ex(n, l, h) _http_persistent_handle_acquire_ex((n), (l), (h)) -- 2.30.2