note 14887 added to function.flock.php
| From: | v at paid1 dot com | Date: | Mon, 20 Aug 2001 00:56:58 +0000 |
| Subject: | note 14887 added to function.flock.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-16900@lists.php.net to get a copy of this message | ||
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);
I have used this function under heavy load (many simultaneous reads and writes) and occassionaly
there is a mysterious glitch. When using append to open the file before locking, occassionaly a file
will DOUBLE the contents! (for example if the count was 123, it would become 123123).
When I change the append to write and remove the truncate, the 'doubling up' disappears --
but now occassionaly a file will turn up empty ("").
http://www.php.net/manual/en/function.flock.php