Re: fopen
| From: | Lars Torben Wilson | Date: | Fri, 15 Feb 2002 17:44:56 +0000 |
| Subject: | Re: fopen | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-84941@lists.php.net to get a copy of this message | ||
On Fri, 2002-02-15 at 08:14, Erik Price wrote:
>
> On Friday, February 15, 2002, at 04:53 AM, Lars Torben Wilson wrote:
>
> > The problem with that is that you have a time lag (perhaps only
> > in microseconds, but it still is a problem) while you're writing
> > the new data to the file. If some other process--say, another
> > invocation of the same script--tries to read from that file while
> > you're still overwriting it--you've got problems, since it'll find
> > only a partially-written file.
> >
> > That's called a 'race condition'. The other method avoids that,
> > since while you're writing data to the temp file, processes just
> > keep using the original. Once you're done, the rename happens
> > atomically, preventing the race condition.
>
> What method do you use to get rid of the temporary file once you've used
> it? It appears, from reading the man page, that the file is still
> present in the directory specified in tempname().
>
>
> Erik <-- doesn't know much about working with files in PHP
unlink(), or you could use tmpfile() instead.
--
Torben Wilson <torben@php.net>
http://www.thebuttlesschaps.com
http://www.hybrid17.com
http://www.inflatableeye.com
+1.604.709.0506