Re: File locking question



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
.



Relevant Pages

  • Re: write with cURL
    ... as the global web server user and thus needs world write permissions ... Hence, any PHP script ran on another account, has the ... global or Apache group (it can still use Apache group to offer web root ...
    (alt.php)
  • Re: Suggestions on creating a File Download area
    ... filename will be able to download the file without paying you anything. ... as the web server wouldn't go out of the /var/www/html ... A php script can read a file outside the document-root, ... use fpassthru() function, of course you can use any of the other file read ...
    (alt.php)
  • Re: write with cURL
    ... This is assuming that the PHP script runs as ... the global web server user (and it surely does given the problem you ... the global web server user and thus needs world write permissions to ... and execute permissions. ...
    (alt.php)
  • Re: A password problem
    ... "Mark Wooding" wrote in message ... > matter for Eve to write a PHP script which runs any arbitrary program ... But if Eve *can't* get the password in clear text (i.e. the web ... If we get rid of the bugs we've identified with web server security, ...
    (sci.crypt)
  • Re: link DB record through browser...
    ... The web browser sends a request to the web server, ... runs the PHP script which sends a query ... http://mindprod.com Java custom programming, consulting and coaching. ...
    (comp.lang.java.databases)