Using advisory file locking : flock « File Directory « PHP






Using advisory file locking

 
<?php
$fh = fopen('guestbook.txt','a')         or die($php_errormsg);
flock($fh,LOCK_EX)                       or die($php_errormsg);
fwrite($fh,$_POST['guestbook_entry']) or die($php_errormsg);
fflush($fh)                              or die($php_errormsg);
flock($fh,LOCK_UN)                       or die($php_errormsg);
fclose($fh)                              or die($php_errormsg);
?>
  
  








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.The file locking mechanism in PHP makes processes queue up for their locks by default