Bug #72517 [Fbk]: file_exists(), is_file() and stat() report wrong result infrequently (~1%)

From: Date: Thu, 14 Jul 2016 10:37:27 +0000
Subject: Bug #72517 [Fbk]: file_exists(), is_file() and stat() report wrong result infrequently (~1%)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202306@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72517&edit=1 ID: 72517 Updated by: ab@php.net Reported by: stgrein at gmail dot com Summary: file_exists(), is_file() and stat() report wrong result infrequently (~1%) Status: Feedback Type: Bug Package: Filesystem function related Operating System: Windows PHP Version: 7.0.8 Block user comment: N Private report: N New Comment: A path of the form \path\to\file is relative to the current drive. The CWD is stored per process in the CRT. Now, if something changes CWD to another drive in one thread, a drive relative path could likely become invalid in another thread. That's the only scenario i can imagine for this bug to reproduce, especially on high load that produces enough concurrency. I barely see a way this bug to be reproduced with the pure core, because chdir() is not used in the thread safe builds. However some non core extension or library could cause this. @stgrein, is this the pure core that reproduces it? It might be quite tricky to trace what's causing the CWD change, maybe procmon or drmemory could give some chance. Thanks. Previous Comments: ------------------------------------------------------------------------ [2016-07-12 15:20:28] requinix@php.net Try a similar test with Apache: /test.php: <?php var_dump(file_exists('/this/file/exists')); /loop.php: <?php $c = 0; for ($i=1; $i<=10000; $i++) { if (strpos(file_get_contents("http://localhost/test.php"), "true")) $c++; } echo $c, "/10000"; ------------------------------------------------------------------------ [2016-07-12 14:01:11] stgrein at gmail dot com Sorry for the late reply. In the CLI the problem does not occur. There I get the 10000 as response for your test case. It occurs only with the php7apache2_4.dll (Apache x64 2.4.20, PHP 7.08 x64 Windows) I cannto re-open the bug: ERROR: You aren't allowed to change a bug to that state ------------------------------------------------------------------------ [2016-07-10 04:22:40] php-bugs at lists dot php dot net No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. ------------------------------------------------------------------------ [2016-06-30 07:50:05] requinix@php.net Here's a cmd command to repeat the test 10k times: (for /l %i in (1,1,10000) do php -r "var_dump(file_exists('/this/file/exists'));") | find /c "true" Naturally it needs to be run from where you have PHP installed (or give the path to php.exe) and you need to change the /this/file/exists path. If you run that, does it show 10000 or something less? What if the system and/or disk is under load? Also, if you're getting this behavior with regular PHP code, are you potentially creating that file first? Because PHP will cache stat information during execution; if you are creating the file then use clearstatcache() before re-testing for the presence of the file. http://php.net/manual/en/function.clearstatcache.php Also, testing with PHP 5.5 or 5.6 would be appreciated. ------------------------------------------------------------------------ [2016-06-29 20:10:28] stgrein at gmail dot com Additional information: I used the VC14 x64 Thread Safe build from windows.php.net ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=72517 -- Edit this bug report at https://bugs.php.net/bug.php?id=72517&edit=1

« previous php.bugs (#202306) next »