|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39138 LOCK_NB for flock() does not work
Submitted: 2006-10-12 14:19 UTC Modified: 2006-10-22 01:00 UTC
Avg. Score:4.8 ± 0.6
Reproduced:12 of 12 (100.0%)
Same Version:3 (25.0%)
Same OS:4 (33.3%)
From: php at koterov dot ru Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.1.6 OS: Windows, Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-10-12 14:19 UTC] php at koterov dot ru
@session_write_close(); // be on the safe side
$f = fopen('/tmp/f.lck', 'a+');
var_dump(flock($f, LOCK_EX | LOCK_NB, $w));

When I run this script concurrently, all results are same: "bool(true) int(0)". Seems LOCK_NB simply ignored.

There is a lot of same bugs (e.g., etc.), but they are closed or outdated.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-12 14:44 UTC]
Not reproducible on Linux.
 [2006-10-13 06:47 UTC] php at koterov dot ru
Ah, on Linux bug is reproducible at version 5.1.1. Sorry, I do not have more recent test machine. On Windows - I've tested 5.1.6, bug is reproducible.
 [2006-10-13 08:34 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-10-13 13:38 UTC] php at koterov dot ru
PHP 5.2.0RC6-dev (cli) (built: Oct 13 2006 12:22:44)

Bug is reproducible.
 [2006-10-13 13:43 UTC]
What kind of Server API do you use and is your web-server threaded or not?
Where can I see the results? (as I'm unable to reproduce it locally)
 [2006-10-13 14:12 UTC] php at koterov dot ru
Thanks for detailed testing.

Server version: Apache/2.0.54
Server built:   Apr 16 2005 14:25:31
Windows XP, NTFS.

I don't know if my server threaded or not; where could I see that?

With command-line php.exe effect is NOT quite reproducible: first process prints "bool(true) int(0)", second - "bool(false) int(0)". (Note that in both cases we have 0 in $w; is it proper or not?)

One time I've got in additional a message: "Failed to start up concurrent users module!" with php.exe, but cannot reproduce this message again now.
 [2006-10-13 14:20 UTC]
Wait, so did you try the snapshot on Linux?
Or are you talking only of Windows now?
 [2006-10-13 19:06 UTC] php at koterov dot ru
I cannot try snapshot on Linux - I have no machine for experiments. And you said that Linux has no problem in new version.

Now we are talking about Windows only.
 [2006-10-14 13:09 UTC]
Where can I see the results? (as I'm unable to reproduce it locally)
 [2006-10-22 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".
 [2007-05-28 10:50 UTC] bugreporter at sigproc dot de

problem might be just due to unclear documentation on how to apply LOCK_NB. The current flock docu says one should "add LOCK_NB to $operation" (i.e. to the second parameter of the function).

A comment on the docu page wants to assure us that neither of the following will work (administrator at proxy-list dot org, 30-Apr-2007 08:30)

flock($fp, LOCK_EX and LOCK_SH); 
flock($fp, LOCK_EX or LOCK_SH);  
flock($fp, LOCK_EX + LOCK_SH);

(Rather separate flock calls should be used.)

So question to the PHP devs: what is the right way to do it?

 [2010-01-14 14:21 UTC] sp at vovochka dot org dot ua
Are you going to fix this bug. It is more than 3 years old! It is reproducable on NTFS.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Feb 28 11:01:24 2021 UTC