note 14887 deleted from function.flock by jimw
| From: | jimw@php.net | Date: | Sat, 08 Dec 2001 19:10:09 +0000 |
| Subject: | note 14887 deleted from function.flock by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22085@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 ("").