The file locking mechanism in PHP makes processes queue up for their locks by default : flock « File Directory « PHP






The file locking mechanism in PHP makes processes queue up for their locks by default

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








Related examples in the same category

1.Locking Files with flock( )
2.If file lock is not available, flock( ) will return immediately with false rather than wait for a lock to become available.
3.Using advisory file locking