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