Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Document touch() doesn't clear the stat cache. #4301

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Crell
Copy link
Contributor

@Crell Crell commented Dec 13, 2024

Thanks to @derickr for pointing this out to me. It drove me batty for days. 😄

Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not unique about touch(). None of the file operations clear the stat cache:

<?php
var_dump(filemtime('/tmp/foo.txt'), filesize('/tmp/foo.txt'));
file_put_contents('/tmp/foo.txt', str_repeat('x', random_int(0, 999)));
clearstatcache();
var_dump(filemtime('/tmp/foo.txt'), filesize('/tmp/foo.txt'));

@Crell
Copy link
Contributor Author

Crell commented Dec 13, 2024

Seems like we should add the same warning to other functions, then. Is it worth making an entity out of it, or just copy-paste-tweak?

@Girgias
Copy link
Member

Girgias commented Dec 13, 2024

We already have the note.clearstatcache entity. Is that insufficient?

@Crell
Copy link
Contributor Author

Crell commented Dec 14, 2024

What is insufficient is my awareness that entity already exists. 😄 Switched to using that, and added touch to the list on the clearstatcache page, which was missing.

<function>fileperms</function>.
<function>filetype</function>,
<function>fileperms</function>, and.
<function>touch</function>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is wrong. This list lists the functions that read from the stat cache. touch() is a setter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says nothing about read/ It just says "Affected."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context is:

When you use stat(), lstat(), or any of the other functions listed in the affected functions list (below), PHP caches the information those functions return in order to provide faster performance.

touch() is not an affected function, because it does not interact with the stat cache at all. It does not (need to) know about it.

@@ -135,6 +135,16 @@ if (!touch('some_file.txt', $time)) {
<refsect1 role="notes">
&reftitle.notes;
&note.filesystem-time-res;
&note.clearstatcache;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And likewise is this change wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then do we need a new entity for statcache impacting write functions? Because the root issue is I didn't realize touch didn't reset the cache, so couldn't understand why my touch() call didn't seem to do anything. So I want something on the touch page to indicate that. You and @Girgias figure out what you want there, I've already made two proposals and both of them someone has objected to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then do we need a new entity for statcache impacting write functions?

None of them impact the statcache (except for unlink(), which automatically clears it according to the manual). But virtually all of them impact the statdata, because writes implicitly affect the mtime (and usually also the file size).

Note that exec() and friends might also affect the statdata, because you could exec('touch foo.txt'). Dom\HTMLDocument::saveHtml() does as well.

I do not see a value-add in adding a reference to the statcache to every function that possibly affects the statdata and as far as I can tell all the functions reading from the statcache have the note already.

</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably list filemtime first, because the mtime is the relevant field that is modified by touch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

touch can modify both properties, so I listed them in alphabetical order.

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.

3 participants