By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,199 Members | 1,458 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,199 IT Pros & Developers. It's quick & easy.

can't understand flock()

P: n/a
I've scoured over manual page for flock on http://in2.php.net/flock but
I can't understand a few things:

1. will flock wait until a different process releases the lock ?
2. please clarify this line:

" If you don't want flock() to block while locking, add LOCK_NB "

what does "block" mean above?

I'd like to use flock() in a manner that when locking attempt fails on
a file (maybe it is alreadly locked by some other process) then the
script wouldn't wait but go on and do something, eg: close the file.

Thanks
Mike

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>I've scoured over manual page for flock on http://in2.php.net/flock but
I can't understand a few things:

1. will flock wait until a different process releases the lock ?
Yes, in blocking mode.
No, in non-blocking mode.
2. please clarify this line:

" If you don't want flock() to block while locking, add LOCK_NB "

what does "block" mean above?
Wait for someone to let go of the lock, if necessary.
In pathological cases, this could take years.
I'd like to use flock() in a manner that when locking attempt fails on
a file (maybe it is alreadly locked by some other process) then the
script wouldn't wait but go on and do something, eg: close the file.


Then you want non-blocking mode.

Gordon L. Burditt
Jul 17 '05 #2

P: n/a
Got it, but EWOULDBLOCK is still confusing.. Any explanation?

Jul 17 '05 #3

P: n/a
>Got it, but EWOULDBLOCK is still confusing.. Any explanation?

EWOULDBLOCK means the call to flock() would have blocked, but you
asked for non-blocking mode, so it's going to immediately return
an error instead. In other words, you didn't get the lock: someone
else has it.

Gordon L. Burditt
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.