#28790 [Opn->Bgs]: file write/close doesn't update file size stat cache
| From: | iliaa@php.net | Date: | Tue, 15 Jun 2004 17:03:35 +0000 |
| Subject: | #28790 [Opn->Bgs]: file write/close doesn't update file size stat cache | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-60962@lists.php.net to get a copy of this message | ||
ID: 28790
Updated by: iliaa@php.net
Reported By: jnoll at prim dot hu
-Status: Open
+Status: Bogus
Bug Type: Filesystem function related
Operating System: Debian GNU/Linux (unstable)
PHP Version: 4.3.6
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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