Don't trust flock. It only works if your file is on the same physical system as your code. Even then, it doesn't always work. Furthermore, flock is only advisory
. The OS doesn't enforce a flock to all processes.
Frankly, all flock does is put a flag on the file. If another process actually bothers to check the flag, the OS will let it know what the state is. If the other process just goes ahead and opens the file anyway, the OS will let it.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?