note 37885 added to function.flock
| From: | "KlausRabensteinvonHeilabr�ck" at rn2 dot php dot net | Date: | Mon, 01 Dec 2003 12:47:43 +0000 |
| Subject: | note 37885 added to function.flock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61202@lists.php.net to get a copy of this message | ||
I'm not quite sure, whether it is possible to create a effective machanism that ensures file
locking by creating something called a "lock-file" (Important: this lock-file isn't
thought as file with contents, it only has symbolic meaning if it exists).
There seem to be several reasons for NOT doing the above:
1. You have to check, whether the lock-file exists
1.1 Do something if it exists
1.2 Do something if it doesn't exist
2. Ensure the lock file has rights that prevent messing up with it from another another program
3. and so on...
Hence, it comes forward that this method is very slow and not effective!!!
The argument "flock() is no good because of differing platform based handlings" fails
because the methods you need to use the above are at least as much dependable on platforms as
flock() is itself.
I'm not commenting on many posters before me for these reasons.
Let's consider you want to write some contents (C) to a file (F). In my opinion a temporay file
(T) with a random filename should store the content you want to write to F. After you successfully
stored C in T you open a stream to F an close it just after you write C in it. If everything went
ok, you can delete T. Otherwise you output a message and encourage the user to try it again. One can
use the contents saved in T as optional recovery data.
This way it is highly impossible that another program is messing up with your data because T's
name can hardly be guessed, and if flock() works on your system, it is locked as well.
Of course, my method extends the meaning of flock(), but I do not see another way how to deal with
problems that might occur when using flock() only.
I hope I wasn't too theoretical.
----
Manual Page -- http://www.php.net/manual/en/function.flock.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37885
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37885&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37885&report=yes
Search -- http://master.php.net/manage/user-notes.php