Re: writing while reading
| From: | Richard Lynch | Date: | Wed, 01 Aug 2001 20:20:19 +0000 |
| Subject: | Re: writing while reading | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60813@lists.php.net to get a copy of this message | ||
> Function chat2file($filename, $str) {
> $fp = fopen("chats/$filename", "a");
> fputs($fp, $str);
> close($fp);
> }
So long as $str is less than, errr, 8K?, this is good on Linux, as the
append will be atomic.
You would want flock here if it's not Linux, or if it wasn't "a".
> Function file2chat($filename) {
> if(file_exists("chats/$filename")) {
> $fd = fopen("chats/$filename", "r");
> flock($fd, LOCK_UN);
You don't need to lock for reading at all. You really don't care if 2
people read at once.
Disclaimer: I *THINK* it's (Linux+append && <8K == atomic)...
--
WARNING richard@zend.com address is an endangered species -- Use
ceo@l-i-e.com
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm