]> granicus.if.org Git - php/commitdiff
add realpath cache inspect functions
authorStanislav Malyshev <stas@php.net>
Tue, 8 Dec 2009 01:35:08 +0000 (01:35 +0000)
committerStanislav Malyshev <stas@php.net>
Tue, 8 Dec 2009 01:35:08 +0000 (01:35 +0000)
NEWS
TSRM/tsrm_virtual_cwd.c
TSRM/tsrm_virtual_cwd.h
ext/standard/basic_functions.c
ext/standard/filestat.c
ext/standard/php_filestat.h
ext/standard/tests/file/realpath_cache.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 095e449d982c7dc13544203e02135491f5c5de86..2632a7ec050580bf04fdcca8bc224bf8b152d672 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ PHP                                                                        NEWS
 - Added support for CURLOPT_CERTINFO. FR #49253.
   (Linus Nielsen Feltzing <linus@haxx.se>)
 - Added client-side server name indication support in openssl. (Arnaud)
+- Added realpath_cache_size() and realpath_cache_get(). (Stas)
 
 - Improved fix for bug #50006 (Segfault caused by uksort()). (Stas)
 
index 3e98a5acc1b1b8840644fb209556b333635ffc36..e150d7fb654ae07de8b4e037c52ada8a10d046b0 100644 (file)
@@ -590,6 +590,22 @@ CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int path_
 }
 /* }}} */
 
+CWD_API int realpath_cache_size() 
+{
+       return CWDG(realpath_cache_size);
+}
+
+CWD_API int realpath_cache_max_buckets() 
+{
+       return (sizeof(CWDG(realpath_cache)) / sizeof(CWDG(realpath_cache)[0]));
+}
+
+CWD_API realpath_cache_bucket** realpath_cache_get_buckets() 
+{
+       return CWDG(realpath_cache);
+}
+
+
 #undef LINK_MAX
 #define LINK_MAX 32
 
index 39ff89e3e04d3a09c7995225db24e2f6fd02a24f..afd4a0ba96605d1b26f0747f575d6753bbb2e47e 100644 (file)
@@ -238,6 +238,9 @@ extern virtual_cwd_globals cwd_globals;
 CWD_API void realpath_cache_clean(TSRMLS_D);
 CWD_API void realpath_cache_del(const char *path, int path_len TSRMLS_DC);
 CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int path_len, time_t t TSRMLS_DC);
+CWD_API int realpath_cache_size();
+CWD_API int realpath_cache_max_buckets();
+CWD_API realpath_cache_bucket** realpath_cache_get_buckets();
 
 /* The actual macros to be used in programs using TSRM
  * If the program defines VIRTUAL_DIR it will use the
index b035782dc35a9dc7703d20a340e881ecc7d58b3d..eac15f3c621c32f483006f11d3ece0ad36d22429 100644 (file)
@@ -1301,6 +1301,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_clearstatcache, 0, 0, 0)
        ZEND_ARG_INFO(0, filename)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO(arginfo_realpath_cache_size, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_realpath_cache_get, 0)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO(arginfo_fileperms, 0)
        ZEND_ARG_INFO(0, filename)
 ZEND_END_ARG_INFO()
@@ -3198,6 +3204,8 @@ const zend_function_entry basic_functions[] = { /* {{{ */
        PHP_FE(disk_total_space,                                                                                                arginfo_disk_total_space)
        PHP_FE(disk_free_space,                                                                                                 arginfo_disk_free_space)
        PHP_FALIAS(diskfreespace,               disk_free_space,                                                arginfo_disk_free_space)
+       PHP_FE(realpath_cache_size,                                                                                             arginfo_realpath_cache_size)
+       PHP_FE(realpath_cache_get,                                                                                              arginfo_realpath_cache_get)
 
        /* functions from mail.c */
        PHP_FE(mail,                                                                                                                    arginfo_mail)
index 735a1d5f3fceff0166d430dc7db897c5fbe86b18..f37f5bb599cdae331ae66ab6193d8ebe567effec 100644 (file)
@@ -1107,6 +1107,44 @@ FileFunction(php_if_lstat, FS_LSTAT)
 FileFunction(php_if_stat, FS_STAT)
 /* }}} */
 
+/* {{{ proto bool realpath_cache_size()
+   Get current size of realpath cache */
+PHP_FUNCTION(realpath_cache_size)
+{
+       RETURN_LONG(realpath_cache_size());
+}
+
+/* {{{ proto bool realpath_cache_get()
+   Get current size of realpath cache */
+PHP_FUNCTION(realpath_cache_get)
+{
+       realpath_cache_bucket **buckets = realpath_cache_get_buckets(), **end = buckets + realpath_cache_max_buckets();
+
+       array_init(return_value);
+       while(buckets < end) {
+               realpath_cache_bucket *bucket = *buckets;
+               while(bucket) {
+                       zval *entry;
+                       MAKE_STD_ZVAL(entry);
+                       array_init(entry);
+
+                       add_assoc_long(entry, "key", bucket->key);
+                       add_assoc_bool(entry, "is_dir", bucket->is_dir);
+                       add_assoc_stringl(entry, "realpath", bucket->realpath, bucket->realpath_len, 1);
+                       add_assoc_long(entry, "expires", bucket->expires);
+#ifdef PHP_WIN32
+                       add_assoc_bool(entry, "is_rvalid", bucket->is_rvalid);
+                       add_assoc_bool(entry, "is_wvalid", bucket->is_wvalid);
+                       add_assoc_bool(entry, "is_readable", bucket->is_readable);
+                       add_assoc_bool(entry, "is_writable", bucket->is_writable);
+#endif
+                       zend_hash_update(Z_ARRVAL_P(return_value), bucket->path, bucket->path_len+1, &entry, sizeof(zval *), NULL);
+                       bucket = bucket->next;
+               }
+               buckets++;
+       }
+}
+
 /*
  * Local variables:
  * tab-width: 4
index 6e3a6774e994f67da67d658f8b91cd65ba2c173f..fa46bc5b927e736c89d6a717242f36e8333fd681 100644 (file)
@@ -24,6 +24,8 @@
 PHP_RINIT_FUNCTION(filestat);
 PHP_RSHUTDOWN_FUNCTION(filestat);
 
+PHP_FUNCTION(realpath_cache_size);
+PHP_FUNCTION(realpath_cache_get);
 PHP_FUNCTION(clearstatcache);
 PHP_FUNCTION(fileatime);
 PHP_FUNCTION(filectime);
diff --git a/ext/standard/tests/file/realpath_cache.phpt b/ext/standard/tests/file/realpath_cache.phpt
new file mode 100644 (file)
index 0000000..1e19486
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+realpath_cache_size() and realpath_cache_get()
+--FILE--
+<?php
+
+var_dump(realpath_cache_size());
+$data = realpath_cache_get();
+var_dump($data[__DIR__]);
+
+echo "Done\n";
+?>
+--EXPECTF--    
+int(%d)
+array(4) {
+  ["key"]=>
+  int(%d)
+  ["is_dir"]=>
+  bool(true)
+  ["realpath"]=>
+  string(%d) "%sfile"
+  ["expires"]=>
+  int(%d)
+}
+Done