If file lock is not available, flock( ) will return immediately with false rather than wait for a lock to become available. : flock « File Directory « PHP






If file lock is not available, flock( ) will return immediately with false rather than wait for a lock to become available.

 
<?
    $fp = fopen("foo.txt", "w");
    if (flock($fp, LOCK_EX | LOCK_NB)) {
            echo "Got lock!\n";
            sleep(10);
            flock($fp, LOCK_UN);
    } else {
            print "Could not get lock!\n";
    }
?>
  
  








Related examples in the same category

1.Locking Files with flock( )
2.Using advisory file locking
3.The file locking mechanism in PHP makes processes queue up for their locks by default