Bug #72930 [Nab]: filesize bug after rewrite.
| From: | frank123m at gmail dot com | Date: | Tue, 23 Aug 2016 12:43:22 +0000 |
| Subject: | Bug #72930 [Nab]: filesize bug after rewrite. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-203511@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72930&edit=1
ID: 72930
User updated by: frank123m at gmail dot com
Reported by: frank123m at gmail dot com
Summary: filesize bug after rewrite.
Status: Not a bug
Type: Bug
Package: Math related
Operating System: ubuntu
PHP Version: 5.6.25
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
well, thanks.
the answer is the filesize function need clearstatcache() to clear its cache.
then it can be used again.
Previous Comments:
------------------------------------------------------------------------
[2016-08-23 12:26:53] frank123m at gmail dot com
hello, did you notice I use the filesize twice? (before write and after)
I didn't store it in a variable.
it should be read the new filesize, so I thought it is a bug that still use the old one.
------------------------------------------------------------------------
[2016-08-23 10:53:31] cmb@php.net
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
The bug is rather in your script. You're reading the file size,
and writing this (increased by one) back to the file. Then you
expect the file size to have increased.
------------------------------------------------------------------------
[2016-08-23 10:36:53] frank123m at gmail dot com
Description:
------------
function hit_count() {
$filename = 'count.txt';
$handle = fopen($filename, 'r');
$current = fread($handle, filesize($filename));
fclose($handle);
$current_inc = $current + 1;
$handle = fopen($filename, 'w');
fwrite($handle, $current_inc);
fclose($handle);
$handle = fopen($filename, 'r');
$current = fread($handle, filesize($filename));
fclose($handle);
echo $current;
}
Test script:
---------------
count.txt:
example: 99->100
echo $current will show 10 instead of 100.
filesize($filename) remain the same after fwrite. its the bug.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72930&edit=1