use Fcntl ':flock'; flock(FH, LOCK_EX); flock(FH, LOCK_UN);