Posted by Malcolm Dew-Jones on 03/09/07 01:56
andy.z@blueyonder.com wrote:
: If 2 people try to access the same text file at the same time to write to
: it - what happens in PHP ?
: What I mean is - presumably the first will be ok -
: But what will the second person actually see in his browser?
: And what will php do about it if not specifically programmed to deal with
: it
: ie whats the default behaviour?
At this point it may be useful to know that if you open a file in _append_
mode on unix/linux then each write statement writes correctly as a single
"unit" at the _current_ end of the file, even if multiple programs are
writing to the file and continually changing the size of the file.
That means that if multiple processes all write one line at a time to
something like a log file then the log file grows one line at a time.
The lines will be in the order they were written, but will not otherwise
interfere with each other. Indeed this is how a basic unix log file
works.
HOWEVER that only helps with simple text files where you can append things
at the end. If you have something like an HTML file then the updates have
to happen in the middle of the file (before the </body></html> for
example.
In that case you need to lock the file before you modify it. You have to
do that yourself. There are lots of examples of what you have to do so I
won't bother trying to remember the exact details here and now.
[Back to original message]
|