php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54453 LOCK_NB works with LOCK_SH when file locked with LOCK_EX ONLY
Submitted: 2011-04-02 18:42 UTC Modified: 2011-04-03 15:08 UTC
Votes:5
Avg. Score:4.6 ± 0.8
Reproduced:4 of 5 (80.0%)
Same Version:2 (50.0%)
Same OS:1 (25.0%)
From: teamerx at gmail dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: 5.3.6 OS: Windows XP Centos Ubuntu (latest
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-04-02 18:42 UTC] teamerx at gmail dot com
Description:
------------
LOCK_NB works with LOCK_SH when file locked with LOCK_EX ONLY
LOCK_NB doe NOT work with LOCK_SH if file is locked with LOCK_SH

LOCK_NB works with LOCK_EX when file locked with LOCK_SH ONLY
LOCK_NB doe NOT work with LOCK_EX if file is locked with LOCK_EX

preferred output : LOCK_NB should work with LOCK_SH or LOCK_EX no matter what lock 
type the file is locked with


Test script:
---------------
code 1:

$x = fopen("flocktest.txt", "a"); 
if (flock($x, LOCK_SH|LOCK_EX|LOCK_NB)) { 
    print "No problems, I got the lock, now I'm going to sit on it."; 
	@fwrite($x, 'ddd');
        sleep(3); 
		
} else { 
    print "Didn't quite get the lock. Quitting now. Good night."; 
} 
fclose($x); 
	

code 2 :
$x = fopen("flocktest.txt", "rb"); 
if ($x){
	if (flock($x, LOCK_SH|LOCK_NB)) { 
    print "No problems, I got the lock, now I'm going to sit on it."; 
	@fwrite($fp, 'ddd');
        sleep(3); 
		
} else { 
    print "Didn't quite get the lock. Quitting now. Good night."; 
} 
fclose($x); 
}


if running code 1 then code 1 , lock NB is not working , if running code 1 then code 2 , lock_nb works
if running code 2 then code 2 , lock_nb does not work , if running code 2 then code 1 lock nb works .


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-03 15:08 UTC] cataphract@php.net
-Package: Output Control +Package: Filesystem function related
 [2013-03-27 21:09 UTC] oxygenus at gmail dot com
Perhaps the method of running the PHP script should be mentioned. If this is not 
reproducible in CLI mode, then I think something else was at fault, not PHP.

http://stackoverflow.com/a/9827159/584490
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Oct 22 04:01:26 2018 UTC