Bug #72666 [Opn]: touch(): stat cache clearing inconsistent between file:// paths and plain paths
Edit report at https://bugs.php.net/bug.php?id=72666&edit=1
ID: 72666
Updated by: ab@php.net
Reported by: phofstetter at sensational dot ch
Summary: touch(): stat cache clearing inconsistent between
file:// paths and plain paths
Status: Open
Type: Bug
Package: Streams related
Operating System: MacOS X and Linux
PHP Version: 7.1.0beta1
Block user comment: N
Private report: N
New Comment:
As mentioned on ML, I'd doubt the removal is justified. The most of usage scenarios only profit
from the caching, while in other cases cache can be explicitly reset. I/O is one of the usual
bottlenecks, even today. So more like expected behavior.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2016-07-25 07:37:00] phofstetter at sensational dot ch
Description:
------------
When calling touch() on a plain path, the stat cache doesn't get cleared. However, when calling
touch() on a 'file://' URL, the stat cache gets cleared by virtue of
php_plain_files_metadata which clears the stat cache after all operations.
This leads to the behaviour as shown in the test script (output available here: https://3v4l.org/0VQIo)
Furthermore: fopen(), fwrite(), fclose() does not clear the stat cache in either case and neither
does file_put_contents().
I would create a PR to fix the touch() case, but in general, it's probably worth reconsidering
the usefulness of the stat-cache these days. Even over an NFS link, when doing nothing but
stat()'ing, you still only lose about 10% performance if you call clearstatcache() after every
stat().
Plus, the cache really only helps when you continuously stat() the same file within the same
request, which probably isn't correct application behaviour anyways.
So in general, I would propose to actually kill the stat cache which would fix this inconsistency as
well :-)
Test script:
---------------
<?php
// doesn't update realpath cache
touch('/tmp/foo');
var_dump(filemtime('/tmp/foo'));
touch('/tmp/foo', 1);
var_dump(filemtime('/tmp/foo'));
// does update the realpath cache
touch('file:///tmp/foo');
var_dump(filemtime('file:///tmp/foo'));
touch('file:///tmp/foo', 1);
var_dump(filemtime('file:///tmp/foo'));
Expected result:
----------------
int(1469202653)
int(1)
int(1469202653)
int(1)
Actual result:
--------------
int(1469202653)
int(1469202653)
int(1469202653)
int(1)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72666&edit=1
Thread (6 messages)