Meta Engineer?

This is available as OS\flock in the www repository.

Acquire or remove an advisory lock on a file descriptor

namespace HH\Lib\OS;

function flock(
  FileDescriptor $fd,
  int $flags,
): void;

See man 2 flock for details. On error, an ErrnoException will be thrown.

A shared lock can also be 'upgraded' to an exclusive lock, however this operation is not guaranteed to be atomic: systems may implement this by releasing the shared lock, then attempting to acquire an exclusive lock. This may lead to an upgrade attempt meaning that a lock is lost entirely, without a replacement, as another process may potentially acquire a lock between these operations.


  • FileDescriptor $fd
  • int $flags a bitmask of LOCK_ flags; one out of LOCK_EX, LOCK_SH, or LOCK_UN must be specified.


  • void