Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

PHP 8.3.17 - Very strange is_file() issue on CLI #17915

Closed
everdio opened this issue Feb 24, 2025 · 2 comments
Closed

PHP 8.3.17 - Very strange is_file() issue on CLI #17915

everdio opened this issue Feb 24, 2025 · 2 comments

Comments

@everdio
Copy link

everdio commented Feb 24, 2025

Description

To reproduce this you can create these 3 files:
test1.php

<?php foreach (\array_fill(0, 10, "test") as $key => $content) { \file_put_contents("test_" . $key . ".tmp", $content); }

test2.php
<?php while(true) { foreach (\array_fill(0, 10, "test") as $key => $content) { $file = "test_" . $key . ".tmp"; echo \is_file($file) . " => " . \file_exists($file) . \PHP_EOL; } sleep(2); }

and test3.php
<?php foreach (\array_fill(0, 10, "test") as $key => $content) { \unlink("test_" . $key . ".tmp"); sleep(2); }

First yuu run test1.php, this just creates 10 dummy files. Then start running test2.php and open another terminal. In that second terminal run test3.php which will remove the files 1 by 1.

test2.php will start outputting as expected, until the very last file, it will keep reporting the final is_file as true while the file is really gone ?

PHP Version

PHP 8.3.17

Operating System

Debian GNU/Linux 12 (bookworm)

@cmb69
Copy link
Member

cmb69 commented Feb 24, 2025

Sounds like a realpath cache issue, and wouldn't probably be a bug, since is_file() results are cached, but file_exists() results are not – oh, that might be Windows only (needs F_OK to be defined; not sure about POSIX systems).

@everdio
Copy link
Author

everdio commented Feb 28, 2025

Thanks, I just checked and it is enabled. I added clearstatcache() in test2.php and this gave me the expected result!

@everdio everdio closed this as completed Feb 28, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants