Re: [PHP] check if file is already in use before fopen

2001-10-04 Thread Brian White

Check out the "flock" fucntion

At 16:20 4/10/2001 -0400, Jason Stechschulte wrote:
>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
>[EMAIL PROTECTED]
>--
>Sorry.  My testing organization is either too small, or too large, depending
>on how you look at it.  :-)
>  -- Larry Wall in <[EMAIL PROTECTED]>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]

-
Brian White
Step Two Designs Pty Ltd - SGML, XML & HTML Consultancy
Phone: +612-93197901
Web:   http://www.steptwo.com.au/
Email: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] check if file is already in use before fopen

2001-10-04 Thread Jason Stechschulte

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
[EMAIL PROTECTED]
--
Sorry.  My testing organization is either too small, or too large, depending
on how you look at it.  :-)
 -- Larry Wall in <[EMAIL PROTECTED]>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]