Skip to content

LocalFilesystemAdapter. Call clearstatcache in several methods#1873

Merged
frankdejonge merged 1 commit intothephpleague:3.xfrom
pvandommelen:local_clearstatcache
Jun 25, 2025
Merged

LocalFilesystemAdapter. Call clearstatcache in several methods#1873
frankdejonge merged 1 commit intothephpleague:3.xfrom
pvandommelen:local_clearstatcache

Conversation

@pvandommelen
Copy link
Copy Markdown
Contributor

Php's statcache caches the results of some file functions like is_file or filesize.

For the visibility() method, a clearstatcache is already used to clear this cache, but this is not the case for several other methods.

Fixes #1826

@frankdejonge
Copy link
Copy Markdown
Member

Can you add a configuration option to opt-in to this behaviour?

@pvandommelen
Copy link
Copy Markdown
Contributor Author

Thanks for the quick reply! Do we really have to have a configuration option for this?

clearstatcache is already used in the visibility method, which would probably also be affected by such an option. Something similar is also implemented in ensureDirectoryExists.

As mentioned in the issue, this commit would mostly reapply an older fix (6f2211c). Though that's on a much older release.

If you'd still like a configuration option, I can add one. But I think we should then move the existing clearstatcache calls behind that check.

@frankdejonge frankdejonge merged commit 9fdd60a into thephpleague:3.x Jun 25, 2025
6 checks passed
@shyim
Copy link
Copy Markdown
Contributor

shyim commented Sep 30, 2025

Would you merge an PR to make this opt-in @frankdejonge?

This change makes stat-cache useless, and tbh when you call exec, the caller should clear stat-cache not the filesystem abstraction on EVERYTHING 😅

@frankdejonge
Copy link
Copy Markdown
Member

@shyim hi, yes that would work! 👍

@pvandommelen
Copy link
Copy Markdown
Contributor Author

No objections from my side to make it configurable.

I would maybe consider this option being opt-out instead of opt-in. Mostly because having no caching would be a reasonable default and there have even been calls to remove the statcache in php itself entirely (https://externals.io/message/115912).

Just to clarify our use case since it is different from the one in the related issue (calling exec). We run a file exists check in a while loop as a low-tech method to detect the status of an external process. For this it is important that there is no cache involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LocalFilesystemAdapter::fileSize(),fileExists(),directoryExists and possible other method uses cached values

3 participants