note 68875 added to function.flock
| From: | jerry at gh33 dot org | Date: | Mon, 14 Aug 2006 16:30:57 +0000 |
| Subject: | note 68875 added to function.flock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115894@lists.php.net to get a copy of this message | ||
Indeed, flock() will not work reliably when the underlying filesystem is NFS. The proper way to
perform file locking, in this case, would be to use PHP's link() function. From the Linux man
page of open():
O_EXCL When used with O_CREAT, if the file already exists it is an
error and the open will fail. In this context, a symbolic link
exists, regardless of where its points to. O_EXCL is broken on
NFS file systems, programs which rely on it for performing lock-
ing tasks will contain a race condition. The solution for per-
forming atomic file locking using a lockfile is to create a
unique file on the same fs (e.g., incorporating hostname and
pid), use link(2) to make a link to the lockfile. If link()
returns 0, the lock is successful. Otherwise, use stat(2) on
the unique file to check if its link count has increased to 2,
in which case the lock is also successful.
----
Server IP: 195.221.21.36
Probable Submitter: 88.191.21.42
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.flock.php
Edit -- https://master.php.net/note/edit/68875
Del: integrated -- https://master.php.net/note/delete/68875/integrated
Del: useless -- https://master.php.net/note/delete/68875/useless
Del: bad code -- https://master.php.net/note/delete/68875/bad+code
Del: spam -- https://master.php.net/note/delete/68875/spam
Del: non-english -- https://master.php.net/note/delete/68875/non-english
Del: in docs -- https://master.php.net/note/delete/68875/in+docs
Del: other reasons-- https://master.php.net/note/delete/68875
Reject -- https://master.php.net/note/reject/68875
Search -- https://master.php.net/manage/user-notes.php