php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27029 filesize() during concurrent file read/write
Submitted: 2004-01-24 05:02 UTC Modified: 2004-01-25 13:08 UTC
From: linke at paralight dot ru Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.4 OS: FreeBSD4.3(ufs) / WinXPpro(ntfs)
Private report: No CVE-ID: None
 [2004-01-24 05:02 UTC] linke at paralight dot ru
Description:
------------
When opened file grows during script run, filesize still report old size. Cached filesize? But clearstatcache() before filesize() can't help.

On FreeBSD 4.3-STABLE there is no this unexpected behaviour - it's all ok without any clearstatcache();

I get my "bbbbbb" on WindowsXP/ntfs when when I use fread($fd_2, 1024) instead of fread($fd_2, filesize('test')).


In production environment i'll get this behavior during concurrent file read/write from two simultaneously running script. I think at leas this behavior must be same at all platforms, so it's a bug.

Reproduce code:
---------------
<?
$fd=fopen('test', 'wb');
fwrite($fd, 'aa');
fclose($fd);

$fd_1=fopen('test', 'rb+');
$fd_2=fopen('test', 'rb+');

fwrite($fd_1, 'bbbbbb');
echo fread($fd_2, filesize('test'));

fclose($fd_1);
fclose($fd_2);
?>


Expected result:
----------------
bbbbbb

Actual result:
--------------
FreeBSD 4.3-STABLE (ufs): 
bbbbbb

Windows XP pro (ntfs):
bb


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-25 13:08 UTC] wez@php.net
Your operating system(s) are reporting the old value because they haven't yet committed the contents -->
try using fflush().  If you already have the file opened,
use fstat().

Note that (especially under windows), doing anything with a file that is opened by some other process is not guaranteed to give you sane results until some unknown time after the other process has released its handle on the file.

Since there is nothing that PHP can do about this, it is
not a PHP bug, so setting status to bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 07:01:28 2024 UTC