Nfs – File locks on an NFS

filesystemslockingnetwork-sharenfs

My server uses NFS (Network File System), and I'm unable to use PHP's flock() -function. Is there a way to lock files on an NFS or is there a need to do so?

Best Answer

The manual page flock(2) had been out of date for a long time, but has since been updated to say (emphasis mine):

Since Linux 2.6.12, NFS clients support flock() locks by emulating them as byte-range locks on the entire file. This means that fcntl(2) and flock() locks do interact with one another over NFS. Since Linux 2.6.37, the kernel supports a compatibility mode that allows flock() locks (and also fcntl(2) byte region locks) to be treated as local; see the discussion of the local_lock option in nfs(5).

That is from the official man-pages web site, http://man7.org/linux/man-pages/man2/flock.2.html which shows the new version from man-pages 4.00

Linux 2.6.12 was released in 2005.

This was originally meant to be a comment on janneb's answer, but I didn't have the reputation at the time. The doc update happened in 2014: http://git.kernel.org/cgit/docs/man-pages/man-pages.git/commit/man2/flock.2?id=e449654fdb3f19aafc569df47d12bffdf6276236