|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[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
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 13:00:02 2025 UTC |
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 .