note 15057 added to function.flock.php
| From: | manuel dot ricca at mail dot pt | Date: | Sun, 26 Aug 2001 00:18:28 +0000 |
| Subject: | note 15057 added to function.flock.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17148@lists.php.net to get a copy of this message | ||
Once more regarding your PHP message about flock:
$fd = fopen($my_file, 'a');
if ( $fd != 0 && flock($fd, LOCK_EX) && ftruncate( $fd, 0) ){
fwrite( $fd, $to_write );
} else {
print 'failed..';
}
fclose($fd);
Shouldn't this be done with LOCK_EX + LOCK_NB. This will guarantee that other processes will
not wait for the lock to be acquired and do the same thing themselves. Also, the file can't be
opened with "w" because other processes will be able to do the same and automatically
clear the file.
I also couldn't do any flocking in win98 and php4. Anyone knows if there's a php version
that works for this?
cheers,
Manuel
http://www.php.net/manual/en/function.flock.php