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