stas                                     Tue, 08 Dec 2009 01:35:08 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=291846

Log:
add realpath cache inspect functions

Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c
    U   php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.h
    U   php/php-src/branches/PHP_5_3/ext/standard/basic_functions.c
    U   php/php-src/branches/PHP_5_3/ext/standard/filestat.c
    U   php/php-src/branches/PHP_5_3/ext/standard/php_filestat.h
    A   php/php-src/branches/PHP_5_3/ext/standard/tests/file/realpath_cache.phpt
    U   php/php-src/trunk/TSRM/tsrm_virtual_cwd.c
    U   php/php-src/trunk/TSRM/tsrm_virtual_cwd.h
    U   php/php-src/trunk/ext/standard/basic_functions.c
    U   php/php-src/trunk/ext/standard/filestat.c
    U   php/php-src/trunk/ext/standard/php_filestat.h
    A   php/php-src/trunk/ext/standard/tests/file/realpath_cache.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/branches/PHP_5_3/NEWS	2009-12-08 01:35:08 UTC (rev 291846)
@@ -21,6 +21,7 @@
 - Added support for CURLOPT_CERTINFO. FR #49253.
   (Linus Nielsen Feltzing <li...@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)


Modified: php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c
===================================================================
--- php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c	2009-12-08 01:35:08 UTC (rev 291846)
@@ -590,6 +590,22 @@
 }
 /* }}} */

+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


Modified: php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.h
===================================================================
--- php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.h	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.h	2009-12-08 01:35:08 UTC (rev 291846)
@@ -238,6 +238,9 @@
 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

Modified: php/php-src/branches/PHP_5_3/ext/standard/basic_functions.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/basic_functions.c	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/branches/PHP_5_3/ext/standard/basic_functions.c	2009-12-08 01:35:08 UTC (rev 291846)
@@ -1301,6 +1301,12 @@
 	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 @@
 	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)

Modified: php/php-src/branches/PHP_5_3/ext/standard/filestat.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/filestat.c	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/branches/PHP_5_3/ext/standard/filestat.c	2009-12-08 01:35:08 UTC (rev 291846)
@@ -1107,6 +1107,44 @@
 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

Modified: php/php-src/branches/PHP_5_3/ext/standard/php_filestat.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/php_filestat.h	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/branches/PHP_5_3/ext/standard/php_filestat.h	2009-12-08 01:35:08 UTC (rev 291846)
@@ -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);

Added: php/php-src/branches/PHP_5_3/ext/standard/tests/file/realpath_cache.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/tests/file/realpath_cache.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/standard/tests/file/realpath_cache.phpt	2009-12-08 01:35:08 UTC (rev 291846)
@@ -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

Modified: php/php-src/trunk/TSRM/tsrm_virtual_cwd.c
===================================================================
--- php/php-src/trunk/TSRM/tsrm_virtual_cwd.c	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/trunk/TSRM/tsrm_virtual_cwd.c	2009-12-08 01:35:08 UTC (rev 291846)
@@ -590,6 +590,22 @@
 }
 /* }}} */

+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


Modified: php/php-src/trunk/TSRM/tsrm_virtual_cwd.h
===================================================================
--- php/php-src/trunk/TSRM/tsrm_virtual_cwd.h	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/trunk/TSRM/tsrm_virtual_cwd.h	2009-12-08 01:35:08 UTC (rev 291846)
@@ -255,6 +255,9 @@
 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

Modified: php/php-src/trunk/ext/standard/basic_functions.c
===================================================================
--- php/php-src/trunk/ext/standard/basic_functions.c	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/trunk/ext/standard/basic_functions.c	2009-12-08 01:35:08 UTC (rev 291846)
@@ -1297,6 +1297,12 @@
 	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()
@@ -3226,6 +3232,8 @@
 	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)

Modified: php/php-src/trunk/ext/standard/filestat.c
===================================================================
--- php/php-src/trunk/ext/standard/filestat.c	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/trunk/ext/standard/filestat.c	2009-12-08 01:35:08 UTC (rev 291846)
@@ -1204,6 +1204,44 @@
 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

Modified: php/php-src/trunk/ext/standard/php_filestat.h
===================================================================
--- php/php-src/trunk/ext/standard/php_filestat.h	2009-12-08 00:25:15 UTC (rev 291845)
+++ php/php-src/trunk/ext/standard/php_filestat.h	2009-12-08 01:35:08 UTC (rev 291846)
@@ -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);

Added: php/php-src/trunk/ext/standard/tests/file/realpath_cache.phpt
===================================================================
--- php/php-src/trunk/ext/standard/tests/file/realpath_cache.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/standard/tests/file/realpath_cache.phpt	2009-12-08 01:35:08 UTC (rev 291846)
@@ -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
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to