Re: [PHP] File locking in PHP???

2004-07-15 Thread Curt Zirzow
* Thus wrote Scott Fletcher:
> Nah!  I'll settle for a simplier one...   file_exists() by checking to see
> if the file exist then spit out the error message.  Meaning the file is in
> use...

Don't use file_exists() for that, it will fail miserable with
racing conditions. a better more portable way would be to use
mkdir():

if (mkdir('mylockdir', 0755) ) {
  // we've obtained a lock 
  // do stuff 

  // and unlock it
  rmdir('mylockdir');
} else {

  // unable to obtain lock

}


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] File locking in PHP???

2004-07-15 Thread Scott Fletcher
Nah!  I'll settle for a simplier one...   file_exists() by checking to see
if the file exist then spit out the error message.  Meaning the file is in
use...

FletchSOD

"Matt M." <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> > Hi!  I saw the php function flock(), since I never used it before so I
> > thought I would ask you folks a couple of questions.
>
> did you read all of the user comments on http://us2.php.net/flock
>
> There is a bunch of good info in there

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] File locking in PHP???

2004-07-15 Thread Scott Fletcher
Yea, read that, very good info there.  Alright, I'll make one from scratch
and do some testing to find what need to be add/change/remove to make it
more a rock solid script.  Boy, it remind me of Perl.

Thanks,
 FletchSOD

"Matt M." <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> > Hi!  I saw the php function flock(), since I never used it before so I
> > thought I would ask you folks a couple of questions.
>
> did you read all of the user comments on http://us2.php.net/flock
>
> There is a bunch of good info in there

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] File locking in PHP???

2004-07-15 Thread Matt M.
> Hi!  I saw the php function flock(), since I never used it before so I
> thought I would ask you folks a couple of questions.

did you read all of the user comments on http://us2.php.net/flock

There is a bunch of good info in there

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] File locking in PHP???

2004-07-15 Thread Scott Fletcher
Hi!  I saw the php function flock(), since I never used it before so I
thought I would ask you folks a couple of questions.

1) Is this function good or is there a better function somewhere that I'm
not aware of?

2) If the flock() activated the file lock then is it possible that I
manually unlock the file?  Like chmod or something through the Linux console
for example.

3) good example of script just in case..

Thanks,
FletchSOD

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] File Locking in PHP.

2001-02-19 Thread David Robley

On Tue, 20 Feb 2001 08:50, Matthew Toledo wrote:
> Hello, I am just starting to use PHP.  I have been using PERL for quite
> some time.  I was wondering if there is any specific FILE LOCKING I
> need to implement to keep more than one person from altering a text
> file at the same time.
>
> For instance, in PERL, you use the flock command to set up an advisory
> file lock.  Lets say that if I have a web page with a text based
> database, and more than one person wants to write to the file at the
> same time.  In perl, if you use flock(FILE, 2).  This causes person A
> to wait while person B writes to the file.  flock(FILE, 8) unlocks the
> file.  Then person A is allowed to write to the file.
>
> Does the perl equivalent of flock happen automatically in PHP?
>
> If not, how do you lock a file?
>
> Is it an advisory lock, or will it cause an error if two people try to
> access the same file at the same time for the same purpose (writing).
>
> Thanks,

The flock() function in PHP seems to do pretty much what you are looking 
for - it allows setting a shared or exclusive lock and you can control 
blocking while locking (at least according to the manual!)

-- 
David Robley| WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet| http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA

-- 
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]




[PHP] File Locking in PHP.

2001-02-19 Thread Matthew Toledo

Hello, I am just starting to use PHP.  I have been using PERL for quite some
time.  I was wondering if there is any specific FILE LOCKING I need to
implement to keep more than one person from altering a text file at the same
time.

For instance, in PERL, you use the flock command to set up an advisory file
lock.  Lets say that if I have a web page with a text based database, and
more than one person wants to write to the file at the same time.  In perl,
if you use flock(FILE, 2).  This causes person A to wait while person B
writes to the file.  flock(FILE, 8) unlocks the file.  Then person A is
allowed to write to the file.

Does the perl equivalent of flock happen automatically in PHP?

If not, how do you lock a file?

Is it an advisory lock, or will it cause an error if two people try to
access the same file at the same time for the same purpose (writing).

Thanks,


===
Matthew Toledo
FrogNet Design & Domain Management
[EMAIL PROTECTED]



--
PHP Language 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]




-- 
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]