From:             jnoll at prim dot hu
Operating system: Debian GNU/Linux (unstable)
PHP version:      4.3.6
PHP Bug Type:     Filesystem function related
Bug description:  file write/close doesn't update file size stat cache

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 bug report at http://bugs.php.net/?id=28790&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28790&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28790&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28790&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28790&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28790&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28790&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28790&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28790&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28790&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28790&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28790&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28790&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28790&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28790&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28790&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28790&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28790&r=float

Reply via email to