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

flock and blocking

P: n/a
If I do flock($fp, LOCK_EX) on a file and another user tries to do
file_get_contents on that file while it's locked, will
file_get_contents block until the lock has been removed?

Oct 31 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Oct 31, 10:16 am, yawnmoth <terra1...@yahoo.comwrote:
If I do flock($fp, LOCK_EX) on a file and another user tries to do
file_get_contents on that file while it's locked, will
file_get_contents block until the lock has been removed?
Also, does file_get_contents lock files? What would happen if a
script tried to lock a file with an exclusive lock (LOCK_EX) while
another instance of the script was reading it? Would the flock
operation block until it had exclusive access? Would the script doing
the reading suddenly stop? Would the script doing the reading
suddenly read different data?

Thanks!

Oct 31 '07 #2

P: n/a
On Oct 31, 8:21 pm, ljb <lba...@pobox.delete.this.comwrote:
terra1...@yahoo.com wrote:
<snip>

The PHP manual says that flock is advisory, except on Windows where it
is mandatory. Advisory locks only apply among processes that agree to use
them, so just doing file_get_contents would not be affected. Mandatory
locks mean no other process can violate the lock, regardless of how it
tries to access the file. flock() itself will block to acquire a lock by
default, but I have no idea if other functions like file_get_contents would
(in a mandatory locking environment). I suspect they would just fail.
Thanks!

Nov 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.