php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #27256 flock() bug
Submitted: 2004-02-14 18:48 UTC Modified: 2004-02-18 14:49 UTC
From: dmitry at koteroff dot ru Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.4 OS: Windows NT, 2000, XP, 2003
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: dmitry at koteroff dot ru
New email:
PHP Version: OS:

 

 [2004-02-14 18:48 UTC] dmitry at koteroff dot ru
Description:
------------
This code does not work on Windows:
 
<?
$f1 = fopen("/tmp/a", "a+b");
flock($f1, LOCK_SH);
$f2 = fopen("/tmp/a", "r+b");
fwrite($f2, "test");
?>
 
It creates zero-length file. On Linux everything is OK.
 
If I delete flock() or call flock($f1, LOCK_UN) just after first flock(), all works correctly.

Flock() is ADVISORY lock, but it works as mandatory lock. Bad luck.

Reproduce code:
---------------
$f1 = fopen("/tmp/a", "a+b");
flock($f1, LOCK_SH);
$f2 = fopen("/tmp/a", "r+b");
fwrite($f2, "test");


Expected result:
----------------
Create non-empty file.

Actual result:
--------------
Creates empty file.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-14 18:56 UTC] gschlossnagle@php.net
flock() is mandatory under winNT and it's derivatives.  
This is a documentation bug.
 [2004-02-14 19:34 UTC] dmitry at koteroff dot ru
Opa. 

But why? If I'm not very wrong, Windows has its own advisory locking API. Why is it not used?

P.S.
I have forgot to say: this behavour is related to all versions op PHP: php4 and php5 too.
 [2004-02-14 19:48 UTC] wez@php.net
There is no advisory locking, only mandatory locking.
 [2004-02-18 14:49 UTC] nlopess@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.


 [2020-02-07 06:12 UTC] phpdocbot@php.net
Automatic comment on behalf of nlopess
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=1906ef1c2afa77d0da12e3088f03fa72bd1a9e0f
Log: fix #27256
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 04:01:34 2025 UTC