note 31274 added to function.flock
| From: | hhw at joymail dot com | Date: | Wed, 16 Apr 2003 04:50:10 +0000 |
| Subject: | note 31274 added to function.flock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46668@lists.php.net to get a copy of this message | ||
Users may find that the following is more useful than flock.
function filelock($operation) {
$lock_file = "filelock.txt";
switch($operation) {
case LOCK_SH: // 1
case LOCK_EX: // 2
do {
clearstatcache();
usleep(rand(5,70));
}
while(file_exists($lock_file));
$fp = fopen2($lock_file, "wb");
fwrite($fp, "blah blah blah");
fclose($fp);
break;
case LOCK_UN: // 3
do {
clearstatcache();
usleep(rand(5,70));
}
while(!file_exists($lock_file));
unlink($lock_file);
break;
default:
break;
}
}
--
http://www.php.net/manual/en/function.flock.php
http://master.php.net/manage/user-notes.php?action=edit+31274
http://master.php.net/manage/user-notes.php?action=delete+31274
http://master.php.net/manage/user-notes.php?action=reject+31274