note 75903 added to function.flock
| From: | commander at graphicore dot de | Date: | Thu, 21 Jun 2007 03:59:45 +0000 |
| Subject: | note 75903 added to function.flock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127845@lists.php.net to get a copy of this message | ||
Notes to some "not so well documented" behaviors of this function.
This is about the differences between winXP and Linux(don't know the distribution Kernel is
2.6.17.8) using LOCK_NB and/or &$wouldblock.
Both systems run PHP 4.4.4. The problem is that the OSs react different.
(All examples work with LOCK_SH insted of LOCK_EX the same way if the locked file is locked for
writing if the file is locked for reading LOCK_SH must return true.)
Without &$wouldblock passed both systems seem to react the same way and as expected.
<?php
//winXP and Linux:
flock($handle,LOCK_EX + LOCK_NB);
//will return FALSE if a lock is on that file otherwise TRUE.
?>
with &$wouldblock passed:
<?php
//winXP:
//nothing changes but the value of $wouldblock
//this is buggy
$wouldblock = NULL;
flock($handle,LOCK_EX + LOCK_NB,&$wouldblock);
//will return FALSE if a lock is on that file otherwise TRUE
//$wouldblock is in every case int 0.
//LINUX:
//new style
$wouldblock = NULL;
flock($handle,LOCK_EX + LOCK_NB,&$wouldblock);
//will return TRUE in every case!
// this is buggy or not documented -- whatever
//$wouldblock is int 1 if a lock is on that file otherwise int 0
?>
We can say: on winXP the third argument does nothing in no case but changing its value to int 0.
On Linux the argument does what its name could indicate it tells us "if the lock would
block" as the documentation says, but it changes the behavior of the function to always return
true.
That's what i've been watching, please report if i am wrong.
The conclusion would be using flock without $wouldblock (don't pass it even if it's NULL)
if you want to have save non blocking locks on win and Linux.
regards
----
Server IP: 217.13.201.10
Probable Submitter: 217.85.101.163
----
Manual Page -- http://www.php.net/manual/en/function.flock.php
Edit -- https://master.php.net/note/edit/75903
Del: integrated -- https://master.php.net/note/delete/75903/integrated
Del: useless -- https://master.php.net/note/delete/75903/useless
Del: bad code -- https://master.php.net/note/delete/75903/bad+code
Del: spam -- https://master.php.net/note/delete/75903/spam
Del: non-english -- https://master.php.net/note/delete/75903/non-english
Del: in docs -- https://master.php.net/note/delete/75903/in+docs
Del: other reasons-- https://master.php.net/note/delete/75903
Reject -- https://master.php.net/note/reject/75903
Search -- https://master.php.net/manage/user-notes.php