From 814bbc76f999ff59c8273aa1404be1c8d762b4ed Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Sat, 25 Jul 2020 21:51:08 +0100 Subject: [PATCH 01/16] Fix bug #28790 Provide an option to disable the stat cache. --- Zend/zend_virtual_cwd.c | 1 + Zend/zend_virtual_cwd.h | 1 + main/main.c | 1 + main/streams/streams.c | 4 ++-- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index ac3d6773b15bc..10093d879800f 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -146,6 +146,7 @@ static void cwd_globals_ctor(virtual_cwd_globals *cwd_g) /* {{{ */ cwd_g->realpath_cache_size = 0; cwd_g->realpath_cache_size_limit = REALPATH_CACHE_SIZE; cwd_g->realpath_cache_ttl = REALPATH_CACHE_TTL; + cwd_g->disable_stat_cache = 0; memset(cwd_g->realpath_cache, 0, sizeof(cwd_g->realpath_cache)); } /* }}} */ diff --git a/Zend/zend_virtual_cwd.h b/Zend/zend_virtual_cwd.h index 84a1562c7789f..bafcc17552e43 100644 --- a/Zend/zend_virtual_cwd.h +++ b/Zend/zend_virtual_cwd.h @@ -222,6 +222,7 @@ typedef struct _virtual_cwd_globals { zend_long realpath_cache_size; zend_long realpath_cache_size_limit; zend_long realpath_cache_ttl; + zend_bool disable_stat_cache; realpath_cache_bucket *realpath_cache[1024]; } virtual_cwd_globals; diff --git a/main/main.c b/main/main.c index 4e7a4f44414c1..f3e2923a73f67 100644 --- a/main/main.c +++ b/main/main.c @@ -758,6 +758,7 @@ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("realpath_cache_size", "4096K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals) STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals) + STD_PHP_INI_BOOLEAN("disable_stat_cache", "0", PHP_INI_SYSTEM, OnUpdateBool, disable_stat_cache, virtual_cwd_globals, cwd_globals) STD_PHP_INI_ENTRY("user_ini.filename", ".user.ini", PHP_INI_SYSTEM, OnUpdateString, user_ini_filename, php_core_globals, core_globals) STD_PHP_INI_ENTRY("user_ini.cache_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, user_ini_cache_ttl, php_core_globals, core_globals) diff --git a/main/streams/streams.c b/main/streams/streams.c index ea0738c82a53f..250563df83799 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1959,7 +1959,7 @@ PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf memset(ssb, 0, sizeof(*ssb)); - if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) { + if (!CWDG(disable_stat_cache) && !(flags & PHP_STREAM_URL_STAT_NOCACHE)) { /* Try to hit the cache first */ if (flags & PHP_STREAM_URL_STAT_LINK) { if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) { @@ -1978,7 +1978,7 @@ PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf if (wrapper && wrapper->wops->url_stat) { ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context); if (ret == 0) { - if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) { + if (!CWDG(disable_stat_cache) && !(flags & PHP_STREAM_URL_STAT_NOCACHE)) { /* Drop into cache */ if (flags & PHP_STREAM_URL_STAT_LINK) { if (BG(CurrentLStatFile)) { From e624ec0bbac7dc84fe3cf194b032cd746c3179b1 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Sun, 26 Jul 2020 15:36:07 +0100 Subject: [PATCH 02/16] Add tests for bug 28790 fix This runs the same php code without `disable_stat_cache` set and with it set. --- ext/standard/tests/file/bug28790.ini | 1 + ext/standard/tests/file/bug28790.phpt | 76 +++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 ext/standard/tests/file/bug28790.ini create mode 100644 ext/standard/tests/file/bug28790.phpt diff --git a/ext/standard/tests/file/bug28790.ini b/ext/standard/tests/file/bug28790.ini new file mode 100644 index 0000000000000..0ed96e771fb53 --- /dev/null +++ b/ext/standard/tests/file/bug28790.ini @@ -0,0 +1 @@ +disable_stat_cache = True diff --git a/ext/standard/tests/file/bug28790.phpt b/ext/standard/tests/file/bug28790.phpt new file mode 100644 index 0000000000000..29361b10338ef --- /dev/null +++ b/ext/standard/tests/file/bug28790.phpt @@ -0,0 +1,76 @@ +--TEST-- +Bug #28790: Add php.ini option to disable stat cache +--CREDITS-- +jnoll +Kevin Lyda +--FILE-- + +--EXPECT-- +lstat: testfile exists. +stat: testfile exists. +lstat: testfile exists (it shouldn't). +stat: testfile exists (it shouldn't). +stat impossiblefile does not exist. +lstat: testfile exists (it shouldn't). +stat: testfile exists (it shouldn't). +is_file(stat): php binary exists. +lstat: testfile exists (it shouldn't). +lstat: php binary exists. +---running with disable_stat_cache = True--- +lstat: testfile exists. +stat: testfile exists. +stat impossiblefile does not exist. +is_file(stat): php binary exists. +lstat: php binary exists. From c0273b57d935961f0297aae2361f8870f9732e5c Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Sun, 26 Jul 2020 15:54:40 +0100 Subject: [PATCH 03/16] Docs for bug 28790 fix Still need to do the ones for the doc-en repo but not quite sure how those work. Suggestions welcome! --- php.ini-development | 6 ++++++ php.ini-production | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/php.ini-development b/php.ini-development index ba30258fd0e6a..ec55e6ff3f5f6 100644 --- a/php.ini-development +++ b/php.ini-development @@ -356,6 +356,12 @@ disable_classes = ; http://php.net/realpath-cache-ttl ;realpath_cache_ttl = 120 +; Allows user to disable the "stat cache." By default php remembers the +; results of the last call to stat() and lstat() and functions that call +; it underneath. Setting this to True disables that behaviour. +; http://php.net/disable-stat-cache +;disable_stat_cache = False + ; Enables or disables the circular reference collector. ; http://php.net/zend.enable-gc zend.enable_gc = On diff --git a/php.ini-production b/php.ini-production index a2a22506a404a..a14ca9076b022 100644 --- a/php.ini-production +++ b/php.ini-production @@ -356,6 +356,12 @@ disable_classes = ; http://php.net/realpath-cache-ttl ;realpath_cache_ttl = 120 +; Allows user to disable the "stat cache." By default php remembers the +; results of the last call to stat() and lstat() and functions that call +; it underneath. Setting this to True disables that behaviour. +; http://php.net/disable-stat-cache +;disable_stat_cache = False + ; Enables or disables the circular reference collector. ; http://php.net/zend.enable-gc zend.enable_gc = On From ef58777213cdceab65a7e0f4192fcf564c654587 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Sun, 26 Jul 2020 17:22:48 +0100 Subject: [PATCH 04/16] Try to properly escape backslashes Windows path use backslashes as directory separators for some reason. Hopefully this quoting will help. --- ext/standard/tests/file/bug28790.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/tests/file/bug28790.phpt b/ext/standard/tests/file/bug28790.phpt index 29361b10338ef..f909681d4e49a 100644 --- a/ext/standard/tests/file/bug28790.phpt +++ b/ext/standard/tests/file/bug28790.phpt @@ -24,9 +24,9 @@ function all_the_stats(\$filename, \$message) { } } -passthru('$php -n -r "touch(\\"$testfile\\");"'); +passthru('$php -n -r \'touch("$testfile");\''); all_the_stats("$testfile", "testfile exists"); -passthru('$php -n -r "unlink(\\"$testfile\\");"'); +passthru('$php -n -r \'unlink("$testfile");\''); all_the_stats("$testfile", "testfile exists (it shouldn't)"); if (!@stat("$impossiblefile")) { print("stat impossiblefile does not exist.\n"); From 745a83be4546d85e35bf1834ffc41e4ae5e9a6cb Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Mon, 27 Jul 2020 00:11:57 +0100 Subject: [PATCH 05/16] Give up escaping file name Just recreate it in a way the shell won't see it. --- ext/standard/tests/file/bug28790.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/tests/file/bug28790.phpt b/ext/standard/tests/file/bug28790.phpt index f909681d4e49a..a27982c2960b3 100644 --- a/ext/standard/tests/file/bug28790.phpt +++ b/ext/standard/tests/file/bug28790.phpt @@ -24,9 +24,9 @@ function all_the_stats(\$filename, \$message) { } } -passthru('$php -n -r \'touch("$testfile");\''); +passthru('$php -n -r \'touch(__DIR__.DIRECTORY_SEPARATOR."bug28790.file");\''); all_the_stats("$testfile", "testfile exists"); -passthru('$php -n -r \'unlink("$testfile");\''); +passthru('$php -n -r \'unlink(__DIR__.DIRECTORY_SEPARATOR."bug28790.file");\''); all_the_stats("$testfile", "testfile exists (it shouldn't)"); if (!@stat("$impossiblefile")) { print("stat impossiblefile does not exist.\n"); From eef8edde00f85fca626b3ae0e184e336c2a8cb67 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Mon, 27 Jul 2020 08:52:31 +0100 Subject: [PATCH 06/16] Revert "Give up escaping file name" This reverts commit 745a83be4546d85e35bf1834ffc41e4ae5e9a6cb. --- ext/standard/tests/file/bug28790.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/tests/file/bug28790.phpt b/ext/standard/tests/file/bug28790.phpt index a27982c2960b3..f909681d4e49a 100644 --- a/ext/standard/tests/file/bug28790.phpt +++ b/ext/standard/tests/file/bug28790.phpt @@ -24,9 +24,9 @@ function all_the_stats(\$filename, \$message) { } } -passthru('$php -n -r \'touch(__DIR__.DIRECTORY_SEPARATOR."bug28790.file");\''); +passthru('$php -n -r \'touch("$testfile");\''); all_the_stats("$testfile", "testfile exists"); -passthru('$php -n -r \'unlink(__DIR__.DIRECTORY_SEPARATOR."bug28790.file");\''); +passthru('$php -n -r \'unlink("$testfile");\''); all_the_stats("$testfile", "testfile exists (it shouldn't)"); if (!@stat("$impossiblefile")) { print("stat impossiblefile does not exist.\n"); From 56e73b1f1cf30ed492d82811d1dbb2ff370598b4 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Mon, 27 Jul 2020 08:55:32 +0100 Subject: [PATCH 07/16] Another pass at Windows path separator problems in test --- ext/standard/tests/file/bug28790.phpt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/standard/tests/file/bug28790.phpt b/ext/standard/tests/file/bug28790.phpt index f909681d4e49a..94eb1af7b84e1 100644 --- a/ext/standard/tests/file/bug28790.phpt +++ b/ext/standard/tests/file/bug28790.phpt @@ -24,9 +24,10 @@ function all_the_stats(\$filename, \$message) { } } -passthru('$php -n -r \'touch("$testfile");\''); +\$testfile = str_replace("\\\\", "/", "$testfile"); +passthru('$php -n -r \'touch("\$testfile");\''); all_the_stats("$testfile", "testfile exists"); -passthru('$php -n -r \'unlink("$testfile");\''); +passthru('$php -n -r \'unlink("\$testfile");\''); all_the_stats("$testfile", "testfile exists (it shouldn't)"); if (!@stat("$impossiblefile")) { print("stat impossiblefile does not exist.\n"); From 690c96104b13127e10d1546bb37de95373bef9f2 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Mon, 27 Jul 2020 10:29:25 +0100 Subject: [PATCH 08/16] Use INI section to simplify test This should reduce the level of escapes required. Clarifies what is actually being tested. --- ext/standard/tests/file/bug28790.cache.phpt | 53 +++++++++++++ ext/standard/tests/file/bug28790.ini | 1 - .../tests/file/bug28790.no-cache.phpt | 50 ++++++++++++ ext/standard/tests/file/bug28790.phpt | 77 ------------------- 4 files changed, 103 insertions(+), 78 deletions(-) create mode 100644 ext/standard/tests/file/bug28790.cache.phpt delete mode 100644 ext/standard/tests/file/bug28790.ini create mode 100644 ext/standard/tests/file/bug28790.no-cache.phpt delete mode 100644 ext/standard/tests/file/bug28790.phpt diff --git a/ext/standard/tests/file/bug28790.cache.phpt b/ext/standard/tests/file/bug28790.cache.phpt new file mode 100644 index 0000000000000..3ce192a30abd7 --- /dev/null +++ b/ext/standard/tests/file/bug28790.cache.phpt @@ -0,0 +1,53 @@ +--TEST-- +Bug #28790: Add php.ini option to disable stat cache (with cache) +--CREDITS-- +jnoll +Kevin Lyda +--FILE-- + +--EXPECT-- +lstat: testfile exists. +stat: testfile exists. +lstat: testfile exists (it shouldn't). +stat: testfile exists (it shouldn't). +stat impossiblefile does not exist. +lstat: testfile exists (it shouldn't). +stat: testfile exists (it shouldn't). +is_file(stat): php binary exists. +lstat: testfile exists (it shouldn't). +lstat: php binary exists. diff --git a/ext/standard/tests/file/bug28790.ini b/ext/standard/tests/file/bug28790.ini deleted file mode 100644 index 0ed96e771fb53..0000000000000 --- a/ext/standard/tests/file/bug28790.ini +++ /dev/null @@ -1 +0,0 @@ -disable_stat_cache = True diff --git a/ext/standard/tests/file/bug28790.no-cache.phpt b/ext/standard/tests/file/bug28790.no-cache.phpt new file mode 100644 index 0000000000000..9085771c39fed --- /dev/null +++ b/ext/standard/tests/file/bug28790.no-cache.phpt @@ -0,0 +1,50 @@ +--TEST-- +Bug #28790: Add php.ini option to disable stat cache (without cache) +--CREDITS-- +jnoll +Kevin Lyda +--INI-- +disable_stat_cache = True +--FILE-- + +--EXPECT-- +lstat: testfile exists. +stat: testfile exists. +stat impossiblefile does not exist. +is_file(stat): php binary exists. +lstat: php binary exists. diff --git a/ext/standard/tests/file/bug28790.phpt b/ext/standard/tests/file/bug28790.phpt deleted file mode 100644 index 94eb1af7b84e1..0000000000000 --- a/ext/standard/tests/file/bug28790.phpt +++ /dev/null @@ -1,77 +0,0 @@ ---TEST-- -Bug #28790: Add php.ini option to disable stat cache ---CREDITS-- -jnoll -Kevin Lyda ---FILE-- - ---EXPECT-- -lstat: testfile exists. -stat: testfile exists. -lstat: testfile exists (it shouldn't). -stat: testfile exists (it shouldn't). -stat impossiblefile does not exist. -lstat: testfile exists (it shouldn't). -stat: testfile exists (it shouldn't). -is_file(stat): php binary exists. -lstat: testfile exists (it shouldn't). -lstat: php binary exists. ----running with disable_stat_cache = True--- -lstat: testfile exists. -stat: testfile exists. -stat impossiblefile does not exist. -is_file(stat): php binary exists. -lstat: php binary exists. From f12b4e242910574d98fac988ec5422c0be75a1fa Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Mon, 27 Jul 2020 16:15:19 +0100 Subject: [PATCH 09/16] Change option to enable_stat_cache There are no boolean "disable_.*" options. However there are a few "enable.*" options that default to "On." --- Zend/zend_virtual_cwd.c | 2 +- Zend/zend_virtual_cwd.h | 2 +- ext/standard/tests/file/bug28790.no-cache.phpt | 2 +- main/main.c | 2 +- main/streams/streams.c | 4 ++-- php.ini-development | 6 +++--- php.ini-production | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 10093d879800f..f283d962e45a6 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -146,7 +146,7 @@ static void cwd_globals_ctor(virtual_cwd_globals *cwd_g) /* {{{ */ cwd_g->realpath_cache_size = 0; cwd_g->realpath_cache_size_limit = REALPATH_CACHE_SIZE; cwd_g->realpath_cache_ttl = REALPATH_CACHE_TTL; - cwd_g->disable_stat_cache = 0; + cwd_g->enable_stat_cache = 1; memset(cwd_g->realpath_cache, 0, sizeof(cwd_g->realpath_cache)); } /* }}} */ diff --git a/Zend/zend_virtual_cwd.h b/Zend/zend_virtual_cwd.h index bafcc17552e43..9292957137756 100644 --- a/Zend/zend_virtual_cwd.h +++ b/Zend/zend_virtual_cwd.h @@ -222,7 +222,7 @@ typedef struct _virtual_cwd_globals { zend_long realpath_cache_size; zend_long realpath_cache_size_limit; zend_long realpath_cache_ttl; - zend_bool disable_stat_cache; + zend_bool enable_stat_cache; realpath_cache_bucket *realpath_cache[1024]; } virtual_cwd_globals; diff --git a/ext/standard/tests/file/bug28790.no-cache.phpt b/ext/standard/tests/file/bug28790.no-cache.phpt index 9085771c39fed..59107e8d2e6ff 100644 --- a/ext/standard/tests/file/bug28790.no-cache.phpt +++ b/ext/standard/tests/file/bug28790.no-cache.phpt @@ -4,7 +4,7 @@ Bug #28790: Add php.ini option to disable stat cache (without cache) jnoll Kevin Lyda --INI-- -disable_stat_cache = True +enable_stat_cache = False --FILE-- wops->url_stat) { ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context); if (ret == 0) { - if (!CWDG(disable_stat_cache) && !(flags & PHP_STREAM_URL_STAT_NOCACHE)) { + if (CWDG(enable_stat_cache) && !(flags & PHP_STREAM_URL_STAT_NOCACHE)) { /* Drop into cache */ if (flags & PHP_STREAM_URL_STAT_LINK) { if (BG(CurrentLStatFile)) { diff --git a/php.ini-development b/php.ini-development index ec55e6ff3f5f6..fb23f46cf47f8 100644 --- a/php.ini-development +++ b/php.ini-development @@ -358,9 +358,9 @@ disable_classes = ; Allows user to disable the "stat cache." By default php remembers the ; results of the last call to stat() and lstat() and functions that call -; it underneath. Setting this to True disables that behaviour. -; http://php.net/disable-stat-cache -;disable_stat_cache = False +; it underneath. Setting this to False disables that behaviour. +; http://php.net/enable-stat-cache +;enable_stat_cache = On ; Enables or disables the circular reference collector. ; http://php.net/zend.enable-gc diff --git a/php.ini-production b/php.ini-production index a14ca9076b022..8828f33491494 100644 --- a/php.ini-production +++ b/php.ini-production @@ -359,8 +359,8 @@ disable_classes = ; Allows user to disable the "stat cache." By default php remembers the ; results of the last call to stat() and lstat() and functions that call ; it underneath. Setting this to True disables that behaviour. -; http://php.net/disable-stat-cache -;disable_stat_cache = False +; http://php.net/enable-stat-cache +;enable_stat_cache = On ; Enables or disables the circular reference collector. ; http://php.net/zend.enable-gc From e209f0d8d10ddad9ebf5409979ec3242a38813a6 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Thu, 2 Sep 2021 10:59:49 +0100 Subject: [PATCH 10/16] Correct the indents in .phpt file .phpt files shouldn't be indented. Fixed bug28790.cache.phpt which tests the functionality for this set of commits. --- ext/standard/tests/file/bug28790.cache.phpt | 58 ++++++++++----------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/ext/standard/tests/file/bug28790.cache.phpt b/ext/standard/tests/file/bug28790.cache.phpt index 3ce192a30abd7..fa869f64ad27f 100644 --- a/ext/standard/tests/file/bug28790.cache.phpt +++ b/ext/standard/tests/file/bug28790.cache.phpt @@ -6,38 +6,38 @@ Kevin Lyda --FILE-- --EXPECT-- From 8e0b2808c4b133d5547891cda024c10578960b3f Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Fri, 3 Sep 2021 14:15:59 +0100 Subject: [PATCH 11/16] Update Zend/zend_virtual_cwd.h Co-authored-by: Nikita Popov --- Zend/zend_virtual_cwd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_virtual_cwd.h b/Zend/zend_virtual_cwd.h index 9292957137756..2a552d2828161 100644 --- a/Zend/zend_virtual_cwd.h +++ b/Zend/zend_virtual_cwd.h @@ -222,7 +222,7 @@ typedef struct _virtual_cwd_globals { zend_long realpath_cache_size; zend_long realpath_cache_size_limit; zend_long realpath_cache_ttl; - zend_bool enable_stat_cache; + bool enable_stat_cache; realpath_cache_bucket *realpath_cache[1024]; } virtual_cwd_globals; From 8140ef1f555d9a68f30fb5bf0533c9064f8e31d4 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Fri, 3 Sep 2021 14:16:05 +0100 Subject: [PATCH 12/16] Update Zend/zend_virtual_cwd.c Co-authored-by: Nikita Popov --- Zend/zend_virtual_cwd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index f283d962e45a6..51de1517434c9 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -146,7 +146,7 @@ static void cwd_globals_ctor(virtual_cwd_globals *cwd_g) /* {{{ */ cwd_g->realpath_cache_size = 0; cwd_g->realpath_cache_size_limit = REALPATH_CACHE_SIZE; cwd_g->realpath_cache_ttl = REALPATH_CACHE_TTL; - cwd_g->enable_stat_cache = 1; + cwd_g->enable_stat_cache = true; memset(cwd_g->realpath_cache, 0, sizeof(cwd_g->realpath_cache)); } /* }}} */ From fac99c927be2ac3642ae63208467c51d56a63d13 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Fri, 3 Sep 2021 15:17:02 +0100 Subject: [PATCH 13/16] Clean up docs, indents and credits Credits are generated from git. Leading indent isn't needed in *.phpt files. Be consistent/correct and use Off instead of False (and correct the True to Off). --- ext/standard/tests/file/bug28790.cache.phpt | 3 - .../tests/file/bug28790.no-cache.phpt | 61 +++++++++---------- php.ini-development | 4 +- php.ini-production | 4 +- 4 files changed, 33 insertions(+), 39 deletions(-) diff --git a/ext/standard/tests/file/bug28790.cache.phpt b/ext/standard/tests/file/bug28790.cache.phpt index fa869f64ad27f..6f9e3a7e4ad90 100644 --- a/ext/standard/tests/file/bug28790.cache.phpt +++ b/ext/standard/tests/file/bug28790.cache.phpt @@ -1,8 +1,5 @@ --TEST-- Bug #28790: Add php.ini option to disable stat cache (with cache) ---CREDITS-- -jnoll -Kevin Lyda --FILE-- -Kevin Lyda --INI-- enable_stat_cache = False --FILE-- --EXPECT-- diff --git a/php.ini-development b/php.ini-development index fb23f46cf47f8..dc653017bbf7b 100644 --- a/php.ini-development +++ b/php.ini-development @@ -356,9 +356,9 @@ disable_classes = ; http://php.net/realpath-cache-ttl ;realpath_cache_ttl = 120 -; Allows user to disable the "stat cache." By default php remembers the +; Allows user to disable the "stat cache". By default php remembers the ; results of the last call to stat() and lstat() and functions that call -; it underneath. Setting this to False disables that behaviour. +; it underneath. Setting this to Off disables that behaviour. ; http://php.net/enable-stat-cache ;enable_stat_cache = On diff --git a/php.ini-production b/php.ini-production index 8828f33491494..78cdeae21bf7b 100644 --- a/php.ini-production +++ b/php.ini-production @@ -356,9 +356,9 @@ disable_classes = ; http://php.net/realpath-cache-ttl ;realpath_cache_ttl = 120 -; Allows user to disable the "stat cache." By default php remembers the +; Allows user to disable the "stat cache". By default php remembers the ; results of the last call to stat() and lstat() and functions that call -; it underneath. Setting this to True disables that behaviour. +; it underneath. Setting this to Off disables that behaviour. ; http://php.net/enable-stat-cache ;enable_stat_cache = On From d07ff728f34dc68f4921130c5e24b75b17fb98cd Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Fri, 3 Sep 2021 15:58:06 +0100 Subject: [PATCH 14/16] Explain tests better Explain in a comment just above each test step why the thing is happening. --- ext/standard/tests/file/bug28790.cache.phpt | 12 +++++++++++- ext/standard/tests/file/bug28790.no-cache.phpt | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ext/standard/tests/file/bug28790.cache.phpt b/ext/standard/tests/file/bug28790.cache.phpt index 6f9e3a7e4ad90..f24d62ba9b373 100644 --- a/ext/standard/tests/file/bug28790.cache.phpt +++ b/ext/standard/tests/file/bug28790.cache.phpt @@ -17,20 +17,30 @@ function all_the_stats($filename, $message) { } } -// Windows can use / for dir separators, so let's do that. +# Windows can use / for dir separators, so let's do that. $qtestfile = str_replace("\\", "/", "$testfile"); + +# This creates a file and should emit stat & lstat messages. passthru($php.' -n -r "touch(\\"'.$qtestfile.'\\");"'); all_the_stats("$testfile", "testfile exists"); + +# This deletes the file and shouldn't emit stat & lstat messages (but does). passthru($php.' -n -r "unlink(\\"'.$qtestfile.'\\");"'); all_the_stats("$testfile", "testfile exists (it shouldn't)"); + +# This stats a non-existent file; still stat/lstats the deleted testfile (shouldn't). if (!@stat("$impossiblefile")) { print("stat impossiblefile does not exist.\n"); } all_the_stats("$testfile", "testfile exists (it shouldn't)"); + +# This is_files an existing file; still can lstat the deleted testfile (shouldn't). if (is_file("$phpfile")) { print("is_file(stat): php binary exists.\n"); } all_the_stats("$testfile", "testfile exists (it shouldn't)"); + +# This lstats an existing file; finally can't stat or lstat the deleted testfile. if (lstat("$phpfile")) { print("lstat: php binary exists.\n"); } diff --git a/ext/standard/tests/file/bug28790.no-cache.phpt b/ext/standard/tests/file/bug28790.no-cache.phpt index 567af1e368aee..7a1c927aae65f 100644 --- a/ext/standard/tests/file/bug28790.no-cache.phpt +++ b/ext/standard/tests/file/bug28790.no-cache.phpt @@ -19,20 +19,30 @@ function all_the_stats($filename, $message) { } } -// Windows can use / for dir separators, so let's do that. +# Windows can use / for dir separators, so let's do that. $qtestfile = str_replace("\\", "/", "$testfile"); + +# This creates a file and should emit stat & lstat messages. passthru($php.' -n -r "touch(\\"'.$qtestfile.'\\");"'); all_the_stats("$testfile", "testfile exists"); + +# This deletes the file and shouldn't emit stat or lstat messages. passthru($php.' -n -r "unlink(\\"'.$qtestfile.'\\");"'); all_the_stats("$testfile", "testfile exists (it shouldn't)"); + +# This stats a non-existent file; still no testfile stat or lstat messages. if (!@stat("$impossiblefile")) { print("stat impossiblefile does not exist.\n"); } all_the_stats("$testfile", "testfile exists (it shouldn't)"); + +# This is_files an existing file; still no testfile stat or lstat messages. if (is_file("$phpfile")) { print("is_file(stat): php binary exists.\n"); } all_the_stats("$testfile", "testfile exists (it shouldn't)"); + +# This lstats an existing file; still no testfile stat or lstat messages. if (lstat("$phpfile")) { print("lstat: php binary exists.\n"); } From fac83f2b7bb04ef5674843950b47965f7c2e9df2 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Fri, 3 Sep 2021 16:15:28 +0100 Subject: [PATCH 15/16] Make the impossible file impossibler. --- ext/standard/tests/file/bug28790.cache.phpt | 2 +- ext/standard/tests/file/bug28790.no-cache.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/tests/file/bug28790.cache.phpt b/ext/standard/tests/file/bug28790.cache.phpt index f24d62ba9b373..97486b0fb2d6e 100644 --- a/ext/standard/tests/file/bug28790.cache.phpt +++ b/ext/standard/tests/file/bug28790.cache.phpt @@ -5,7 +5,7 @@ Bug #28790: Add php.ini option to disable stat cache (with cache) $php = '"'.getenv('TEST_PHP_EXECUTABLE').'"'; $phpfile = getenv('TEST_PHP_EXECUTABLE'); -$impossiblefile = $phpfile.DIRECTORY_SEPARATOR.'bug28790.impossible'; +$impossiblefile = __DIR__.DIRECTORY_SEPARATOR.'bug28790.cache.phpt'.DIRECTORY_SEPARATOR.'impossible'; $testfile = __DIR__.DIRECTORY_SEPARATOR.'bug28790.file'; function all_the_stats($filename, $message) { diff --git a/ext/standard/tests/file/bug28790.no-cache.phpt b/ext/standard/tests/file/bug28790.no-cache.phpt index 7a1c927aae65f..fc9b71846bd86 100644 --- a/ext/standard/tests/file/bug28790.no-cache.phpt +++ b/ext/standard/tests/file/bug28790.no-cache.phpt @@ -7,7 +7,7 @@ enable_stat_cache = False $php = '"'.getenv('TEST_PHP_EXECUTABLE').'"'; $phpfile = getenv('TEST_PHP_EXECUTABLE'); -$impossiblefile = $phpfile.DIRECTORY_SEPARATOR.'bug28790.impossible'; +$impossiblefile = __DIR__.DIRECTORY_SEPARATOR.'bug28790.no-cache.phpt'.DIRECTORY_SEPARATOR.'impossible'; $testfile = __DIR__.DIRECTORY_SEPARATOR.'bug28790.file'; function all_the_stats($filename, $message) { From c91980b386371ebf6afec5aba2a67bb84f29d5d3 Mon Sep 17 00:00:00 2001 From: Kevin Lyda Date: Fri, 3 Sep 2021 16:17:45 +0100 Subject: [PATCH 16/16] And now more succinctly impossibler. --- ext/standard/tests/file/bug28790.cache.phpt | 2 +- ext/standard/tests/file/bug28790.no-cache.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/tests/file/bug28790.cache.phpt b/ext/standard/tests/file/bug28790.cache.phpt index 97486b0fb2d6e..c05f935483d45 100644 --- a/ext/standard/tests/file/bug28790.cache.phpt +++ b/ext/standard/tests/file/bug28790.cache.phpt @@ -5,7 +5,7 @@ Bug #28790: Add php.ini option to disable stat cache (with cache) $php = '"'.getenv('TEST_PHP_EXECUTABLE').'"'; $phpfile = getenv('TEST_PHP_EXECUTABLE'); -$impossiblefile = __DIR__.DIRECTORY_SEPARATOR.'bug28790.cache.phpt'.DIRECTORY_SEPARATOR.'impossible'; +$impossiblefile = __FILE__.DIRECTORY_SEPARATOR.'bug28790.impossible'; $testfile = __DIR__.DIRECTORY_SEPARATOR.'bug28790.file'; function all_the_stats($filename, $message) { diff --git a/ext/standard/tests/file/bug28790.no-cache.phpt b/ext/standard/tests/file/bug28790.no-cache.phpt index fc9b71846bd86..1abb066cd7e6a 100644 --- a/ext/standard/tests/file/bug28790.no-cache.phpt +++ b/ext/standard/tests/file/bug28790.no-cache.phpt @@ -7,7 +7,7 @@ enable_stat_cache = False $php = '"'.getenv('TEST_PHP_EXECUTABLE').'"'; $phpfile = getenv('TEST_PHP_EXECUTABLE'); -$impossiblefile = __DIR__.DIRECTORY_SEPARATOR.'bug28790.no-cache.phpt'.DIRECTORY_SEPARATOR.'impossible'; +$impossiblefile = __FILE__.DIRECTORY_SEPARATOR.'bug28790.impossible'; $testfile = __DIR__.DIRECTORY_SEPARATOR.'bug28790.file'; function all_the_stats($filename, $message) {