ID: 28790 Comment by: phpbugs at spam dot raszi dot hu Reported By: jnoll at prim dot hu Status: Assigned Bug Type: Feature/Change Request Operating System: Debian GNU/Linux (unstable) PHP Version: 4.3.6 Assigned To: pollita New Comment:
It would be better if the file modification functions invalidate not the whole statcache, only the entry of the modified file. Previous Comments: ------------------------------------------------------------------------ [2004-06-16 16:29:51] [EMAIL PROTECTED] Ilia was perhaps a bit short winded in his response... This was actually discussed within the context of a feature change as well and was turned down on the basis that it would create unnecessary slowdowns without significant gain. You should be aware when you're making multiple stat family calls to the same file and call clearstatcache() accordingly. If you're uncertain, then just call it anyway. However, that said it may be prudent to introduce an .ini option to disable the cache altogether now that stat calls work on arbitrary wrappers. Let's leave this option open for PHP 5.1 for now. ------------------------------------------------------------------------ [2004-06-16 16:10:36] jnoll at prim dot hu Okay, let me change this to a feature request! After fclose(), the stat cache for that file should be cleared. Also, unlink and maybe copy should do this. If a function is KNOWN to change file stat data, it should clear the cache. The problem is that even a file_exists() call caches the data (including the file size!), and this is easy to overlook, when you have a bigger system. ------------------------------------------------------------------------ [2004-06-15 19:03:34] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This is to be expected. ------------------------------------------------------------------------ [2004-06-15 15:43:13] jnoll at prim dot hu Description: ------------ The problem is the following: 1. open a file for writing or appending 2. append a character (or anything) to that file 3. close file 4. get the file size with stat or filesize ERROR: this will return the OLD size, before writing If you do a clearstatcache(), the filesize will be the NEW size (the expected result) Reproduce code: --------------- <? $filename = "/tmp/stattest"; // initialise if (!file_exists($filename)) { $f = fopen($filename,"w"); fclose($f); echo "Reload, please."; exit; } $fs = filesize($filename); $fstat = stat($filename); echo "START: $fs, ".$fstat['size']."<BR>"; $f = fopen($filename,"a"); fputs($f,"x"); fclose($f); /** * bad result: this should be 1 byte more than the previous * BUT IT IS THE SAME!!! */ $fs = filesize($filename); $fstat = stat($filename); echo "AFTER(BAD): $fs, ".$fstat['size']."<BR>"; // force a clear clearstatcache(); /** * good result after clearstatcache (why???) */ $fs = filesize($filename); $fstat = stat($filename); echo "AFTER(GOOD): $fs, ".$fstat['size']."<BR>"; ?> Expected result: ---------------- START: 145, 145 AFTER(BAD): 145, 145 AFTER(GOOD): 146, 146 If AFTER(BAD) is less than AFTER(GOOD) value, that means PHP is buggy. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28790&edit=1
