Re: File locking question
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 27 Jun 2008 07:45:15 GMT
Richard Walker <toolate@xxxxxxxxxxxxxxx> wrote:
The php program gets the file using http ie its url thus:
$x=file_get_contents("http://80.229.151.169/sscwsa1.dat");
-the data logger writes the file into the Apache document directory ready
to be pulled.
So the actual "reader" is the web server on the machine the logger
is running on.
I'm trying to understand the sequence of events when Linux
writes the file - I don't know whether the OS would serve up an empty
file, part file or error if the http request came in at just the wrong
moment...
That can happen. There's a certain chance that the logger opens
the file but didn't write any data into it and at that moment the
web server reads the file and finds no data in it, resulting in
the PHP script receiving an empty string. Or the logger may only
have written parts of the file when the web server reads it and
transfers the already available data. The simplest way to avoid
that would be to have the writer open a file with a different
name and only when it has written out all date rename it. Even
if the web server is still in the process of reading the old
version of the file when the logger renames the file nothing
really bad can happen since the old file ontinues to exist
(although without a name) until the web server closes it. Thus
the PHP script will always get consistent data (albeit with a
small chance that there's already a newer version of the file
the moment it receives the data).
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- References:
- File locking question
- From: Richard Walker
- Re: File locking question
- From: Jens Thoms Toerring
- Re: File locking question
- From: Richard Walker
- File locking question
- Prev by Date: Re: phtread_create while pthread_cond_timedwait in gdb
- Next by Date: Re: Tftp server problem
- Previous by thread: Re: File locking question
- Next by thread: Re: File locking question
- Index(es):
Relevant Pages
|