Re: check if file is already in use before fopen
| From: | Jason Stechschulte | Date: | Thu, 04 Oct 2001 20:20:36 +0000 |
| Subject: | Re: check if file is already in use before fopen | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-69974@lists.php.net to get a copy of this message | ||
On Thu, Oct 04, 2001 at 11:10:56AM -0400, Matthew Luchak wrote:
> Is there a way to verify if a file is in use by another user before
> fopening it?
As far as I know this is something you have to program in yourself. If
you are only worried about your programs accessing the file, then it is
a good idea to create a lock file. Before you access a file called
mydata, check for a file called mydata.lock. If that exists, then the
file is in use, so wait and check later. If it does not exist, create a
file called mydata.lock, open mydata, do with it as you please, close
mydata, and delete mydata.lock.
You also have to be prepared to handle a situation where your program
stops before removing the lock file. Usually with PHP, it is much
easier to just use a database so all this file locking is dealt with by
the database and not you.
--
Jason Stechschulte
jpstech@unoh.edu
--
Sorry. My testing organization is either too small, or too large, depending
on how you look at it. :-)
-- Larry Wall in <1991Apr22.175438.8564@jpl-devvax.jpl.nasa.gov>