note 74829 added to function.flock
| From: | administrator at proxy-list dot org | Date: | Mon, 30 Apr 2007 00:30:10 +0000 |
| Subject: | note 74829 added to function.flock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125965@lists.php.net to get a copy of this message | ||
Hello,
I want to give an example how to lock file with two or more flags (for example reading and writing).
IMPORTANT: each locking should be done separately, the correct way of using flock() is:
<?php
flock($fp, LOCK_EX);
flock($fp, LOCK_SH);
?>
and NOT like these:
<?php
flock($fp, LOCK_EX and LOCK_SH);
flock($fp, LOCK_EX or LOCK_SH);
flock($fp, LOCK_EX + LOCK_SH);
?>
Furthermore if someone has not pay attention to functionâs description - flock does not lock
any file in the right way. The file is still accessible for reading/writing, in other words these
functions: file(), file_get_contents() and even fopen($file, ârâ) will ignore the lock.
I think PHP mechanism works something like this: as soon as file lock was successful, the function
flock() writes somewhere (in its own âDBâ for example) that file handle is locked with
some flag and nothing more. It is up to the developer to check if file is locked or not before doing
any operations.
Hope this post makes clear the flock() functionâs working principles.
Regards
Vitali Simsive
----
Server IP: 69.147.83.197
Probable Submitter: 212.72.146.171
----
Manual Page -- http://www.php.net/manual/en/function.flock.php
Edit -- https://master.php.net/note/edit/74829
Del: integrated -- https://master.php.net/note/delete/74829/integrated
Del: useless -- https://master.php.net/note/delete/74829/useless
Del: bad code -- https://master.php.net/note/delete/74829/bad+code
Del: spam -- https://master.php.net/note/delete/74829/spam
Del: non-english -- https://master.php.net/note/delete/74829/non-english
Del: in docs -- https://master.php.net/note/delete/74829/in+docs
Del: other reasons-- https://master.php.net/note/delete/74829
Reject -- https://master.php.net/note/reject/74829
Search -- https://master.php.net/manage/user-notes.php