|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #54129 using LOCK_NB whilst aquiring a lock with flock() does work on windows
Submitted: 2011-03-01 16:59 UTC Modified: 2020-11-18 15:01 UTC
Avg. Score:3.4 ± 1.4
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:3 (60.0%)
From: scope at planetavent dot de Assigned: cmb (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.3.5 OS: Windows Server 2008 (x64)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
37 + 17 = ?
Subscribe to this entry?

 [2011-03-01 16:59 UTC] scope at planetavent dot de
The online documentation states that LOCK_NB to achieve a non-blocking lock-attempt is not supported on windows.

The given test script, if started twice, just returns stating that the lock can not be aquired. Therefor, since it does not block, using LOCK_NB seems to work on windows and the documentation should be updated accordingly. If this is not the expected behaviour, the documentation should reflect the possible situations, where using LOCK_NB does indeed not work.

Furthermore the statement "The automatic unlocking when the file's resource handle is closed was removed. Unlocking now always has to be done manually." should be checked. My test show that closing the file pointer with fclose() does release the lock.

Test script:

$lockfile = 'dummy.lock';

$fp = fopen( $lockfile, 'w+' );

if ( !$fp )
	  echo "unable to open lockfile\n";

if ( !flock( $fp, LOCK_EX | LOCK_NB ) )
	echo "unable to aquire lock\n";

sleep( 10 );

Expected result:
According to documentation, script should block (since LOCK_NB is not supported)

Actual result:
flock does not block


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-30 21:52 UTC]
-Type: Bug +Type: Documentation Problem -Package: Documentation problem +Package: Filesystem function related
 [2015-04-13 19:59 UTC]
-Assigned To: +Assigned To: peehaa
 [2017-10-24 06:27 UTC]
-Status: Assigned +Status: Open -Assigned To: peehaa +Assigned To:
 [2020-11-18 15:01 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-11-18 15:01 UTC]
These issues have already been fixed in the meantime.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Mar 31 01:03:44 2023 UTC