php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21120 fflush doesn`t work
Submitted: 2002-12-20 16:01 UTC Modified: 2002-12-22 09:02 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: rashid@php.net Assigned:
Status: Wont fix Package: Filesystem function related
PHP Version: 4.2.3 OS: win2k pro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rashid@php.net
New email:
PHP Version: OS:

 

 [2002-12-20 16:01 UTC] rashid@php.net
this is not the same as
http://bugs.php.net/bug.php?id=19711 :)

the following code on my platform displays:
File size: 0, written: 2890
File size: 2890, written: 2890

as far as i know fflush should flush output to file at the moment of calling :] moving the line with flcose to the end of script causes that also the second display shows
File size: 0, written: 2890
it looks for me that fflush doesn`t work and all flushing is done during file closing.
tested it under linux also - both variants are done ok there:
File size: 2890, written: 2890
File size: 2890, written: 2890 

$str = '';
for($i = 0;$i < 1000;$i++) {
	$str .= $i;
}

$fp = fopen('test.txt', 'wb');
$written = fwrite($fp, $str);
fflush($fp);
clearstatcache();
$size = filesize('test.txt');
echo 'File size: '.$size.', written: '.$written.'<br>';
fclose($fp);
clearstatcache();
$size = filesize('test.txt');
echo 'File size: '.$size.', written: '.$written.'<br>';

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-21 12:10 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


 [2002-12-21 13:19 UTC] rashid at ds dot pg dot gda dot pl
no changes with latest windows build (PHP Version 4.4.0-dev)
 [2002-12-22 09:02 UTC] wez@php.net
More of a "can't fix".

PHP is fflush()ing correctly, which merely causes any data buffered in a FILE* to be sent to the OS at that time.
It is up to the OS to decide when to write the data to disk.

If you sleep(1) after the fflush() call, the script works as you described, at least on my WinXP box.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC