note 31274 deleted from function.flock by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 00:49:02 +0000 |
| Subject: | note 31274 deleted from function.flock by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155436@lists.php.net to get a copy of this message | ||
Note Submitter: hhw at joymail dot com
----
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;
}
}