RE: [PHP] reading/writing flatfiles with simultaneous users?

From: Date: Wed, 27 Sep 2000 10:57:07 +0000
Subject: RE: [PHP] reading/writing flatfiles with simultaneous users?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-17769@lists.php.net to get a copy of this message
> My question is, does > php only let one instance of a script execution open and read > a flatfile at > a time? No, you have to handle it. > Obviously a flatfile has severe design limitations > compared to a > database, but can it be kept accurate enough with proper > programming methods? Yes: $fp = fopen('your.file.txt', 'a'); flock($fp, 2); fseek($fp, filesize('your.file.txt')); fwrite($fp, 'Some text'."\r\n"); flock($fp, 3); fclose($fp); Thats the rough gist. Could be an error or two in there though. Basically, it opens the file, gains a write lock, seeks to the end of the file (since between opening it and getting the lock the endpoint may have changed), writes some text, releases the lock and closes the file. HTH -- Richard Heyes http://www.heyes-computing.net/scripts/

« previous php.general (#17769) next »