You are asking:
is there any chance that someone else will edit the file between calling fopen and calling flock? same question for fread
Yes, no, maybe. Short answer: assume yes and proceed with caution.
Yes, the fact is that traditional flock () -blocking is just advisory, so other processes (or even the same process) can freely ignore locks. In practice, this is not a problem, since flock () is used by good client code - you do not read until you get LOCK_SH, and you do not write if you did not receive LOCK_EX - specific files.
No, in this PHP implementation of flock () may be required on certain operating systems, in the documentation , which may also require support from the file system (for example, as in the mand option on Linux). Thus, other processes could not ignore these locks.
It is possible that the thread subsystem in PHP 5 implements some accounting blocking beyond the limits provided by the operating system. This can, for example, prevent the same process (but not another), if its own other advisory locks are not taken into account. Behavior may surprise some. However, such a lock will not be mandatory between unrelated processes.
For portability, just assume the weakest semantics (βyesβ above) and limit flock () to the correct code on specially created lock files of the application selected in advance.
pilcrow
source share