- use a HashTable to stat persistent handles
authorMichael Wallner <mike@php.net>
Wed, 31 Jan 2007 12:14:07 +0000 (12:14 +0000)
committerMichael Wallner <mike@php.net>
Wed, 31 Jan 2007 12:14:07 +0000 (12:14 +0000)
- show p. handles with phpinfo

http.c
http_functions.c
http_persistent_handle_api.c
php_http_persistent_handle_api.h

diff --git a/http.c b/http.c
index fc7f15a3964361f984200bc6403ebf905642351e..f0ffeae62d1648c58c288db26e319cac796eb435 100644 (file)
--- 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();
        
index 8941a93f3e1d7191f27fdde6df41fdd712d13dc5..511230eaedef4ab1f63b7884db0b6f9f2eb65b2b 100644 (file)
@@ -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();
        }
 }
 /* }}} */
index 159d378f50b1870089bb2e0c01aeb29288ea5b39..c89c53980d45dc29f26ac682bfdd65b6557da3c8 100644 (file)
@@ -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)
index 661c8e13f2eea449337d069680b8c1a74393a103..27d640f314e5b222c978c0b20ff66c94a267235d 100644 (file)
@@ -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))