php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61436 Missing fflush() in flock() LOCK_EX example
Submitted: 2012-03-19 14:41 UTC Modified: 2012-03-20 07:58 UTC
From: blewis at eatonvance dot com Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Windows 2008
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: blewis at eatonvance dot com
New email:
PHP Version: OS:

 

 [2012-03-19 14:41 UTC] blewis at eatonvance dot com
Description:
------------
---
From manual page: http://www.php.net/function.flock#refsect1-function.flock-
examples
---
Example should be modified to add fflush() as below.  There is no point in 
gaining an exclusive lock if you release it before flushing output.

<?php

$fp = fopen("/tmp/lock.txt", "r+");

if (flock($fp, LOCK_EX)) { // do an exclusive lock
    ftruncate($fp, 0); // truncate file
    fwrite($fp, "Write something here\n");
    fflush($fp); // flush output before releasing lock
    flock($fp, LOCK_UN); // release the lock
} else {
    echo "Couldn't get the lock!";
}

fclose($fp);

?>

Actual result:
--------------
Saw a corrupted file that seems to indicate that output is not automatically 
flushed when an exclusive lock is released.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-20 07:27 UTC] aharvey@php.net
That is a really good point.
 [2012-03-20 07:27 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Package: *General Issues +Package: Documentation problem -Assigned To: +Assigned To: aharvey
 [2012-03-20 07:58 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=324378
Log: Fix doc bug #61436 (Missing fflush() in flock() LOCK_EX example).
 [2012-03-20 07:58 UTC] aharvey@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2012-03-20 07:58 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 12:00:01 2026 UTC