Bug #53064 [Opn->Bgs]: filesize return 0 after is_file
| From: | iliaa@php.net | Date: | Mon, 13 Dec 2010 16:22:15 +0000 |
| Subject: | Bug #53064 [Opn->Bgs]: filesize return 0 after is_file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-156968@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53064&edit=1
ID: 53064
Updated by: iliaa@php.net
Reported by: mraaijmakers at gmail dot com
Summary: filesize return 0 after is_file
-Status: Open
+Status: Bogus
Type: Bug
Package: Filesystem function related
Operating System: Linux Ubuntu
PHP Version: 5.2.14
Block user comment: N
Private report: N
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
Previous Comments:
------------------------------------------------------------------------
[2010-10-15 03:15:15] crrodriguez at opensuse dot org
Just for the sake of completeness, other than the already mentioned
stale stat
cache you are doing it wrong.
fwrite does not imply fflush() and fclose() does not imply fsync() (and
PHP does
not fsync/fdatasync the file on close or provide direct functionality to
do so
unfortunately)
------------------------------------------------------------------------
[2010-10-14 18:12:19] cataphract@php.net
read: negligible
------------------------------------------------------------------------
[2010-10-14 18:11:29] cataphract@php.net
That's just stale stat cache. This will work:
<?php
$filename = dirname(__FILE__) . '/test.txt';
$fh = fopen($filename, 'w+');
$isFile = is_file($filename);
fwrite($fh, 'some data goes here!');
fclose($fh);
clearstatcache(false, $filename);
var_dump($isFile, file_get_contents($filename), filesize($filename));
I'm not closing because maybe there's a way to invalidate the cache for
that file with a negligent performance penalty.
------------------------------------------------------------------------
[2010-10-14 08:38:22] mraaijmakers at gmail dot com
Description:
------------
When using is_file() on a file which is open via fopen(), the filesize()
function returns 0, even after fclose() is called; see test script.
Test script:
---------------
$filename = dirname(__FILE__) . '/test.txt';
$fh = fopen($filename, 'w+');
$isFile = is_file($filename);
fwrite($fh, 'some data goes here!');
fclose($fh);
var_dump($isFile, file_get_contents($filename), filesize($filename));
Expected result:
----------------
boolean true
string 'some data goes here!' (length=20)
int 20
Actual result:
--------------
boolean true
string 'some data goes here!' (length=20)
int 0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53064&edit=1