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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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: Fri Apr 26 12:01:30 2024 UTC