|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46023 appending data twice to file
Submitted: 2008-09-08 14:01 UTC Modified: 2008-11-01 01:00 UTC
Avg. Score:4.3 ± 0.9
Reproduced:7 of 7 (100.0%)
Same Version:3 (42.9%)
Same OS:2 (28.6%)
From: richard dot kuchar at gmail dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.2CVS-2008-09-08 (snap) OS: Debian (etch)
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.
Block user comment
Status: Assign to:
Bug Type:
From: richard dot kuchar at gmail dot com
New email:
PHP Version: OS:


 [2008-09-08 14:01 UTC] richard dot kuchar at gmail dot com
opening file in append mode and writing to file wrote data twice to 

Reproduce code:
$filename = 'test.txt';
$somecontent = "Add this to the file\n";

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
  echo "Cannot open file ($filename)";

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
  echo "Cannot write to file ($filename)";



Expected result:
in 'test.txt':
Add this to the file\n

Actual result:
in 'test.txt':
Add this to the file\nAdd this to the file\n


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-08 23:45 UTC]
Do you have deleted the file before running again?
 [2008-09-09 09:11 UTC] richard dot kuchar at gmail dot com
Yes, I delete file before running script every time
 [2008-10-24 15:48 UTC]
I can not reproduce this with current CVS checkout of PHP_5_2 branch and using CLI. How do you run the script?
 [2008-11-01 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Jun 15 07:01:23 2021 UTC