note 29500 added to function.flock
| From: | carl at rack1 dot php dot net | Date: | Sat, 15 Feb 2003 16:31:25 +0000 |
| Subject: | note 29500 added to function.flock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44007@lists.php.net to get a copy of this message | ||
As flock() doesn't work over NFS (whereas fcntl() does, but there's no PHP interface for
that), you may have to provide some sort of backup locking system if for one reason or other you
need to use NFS (or VFAT, but as the documentation points out it's antiquated). One way of
achieving this is to use a relational database. If you have a table T with an integer column cnt and
a _single_ row, you can:
UPDATE T set cnt = cnt + 1 WHERE cnt >= 0
to obtain a shared lock (and of course you need to verify that there was one affected row). For an
exclusive lock:
UPDATE T set cnt = -1 WHERE cnt = 0
This scheme has two problems: You rely on the script to be able to release locks before exiting, and
there is no way to wait for a lock (except polling). On the whole, if you can use flock() instead,
use flock().
--
http://www.php.net/manual/en/function.flock.php
http://master.php.net/manage/user-notes.php?action=edit+29500
http://master.php.net/manage/user-notes.php?action=delete+29500
http://master.php.net/manage/user-notes.php?action=reject+29500