The following files exists in this folder. Click to view.
flock.php1 lines ASCII Unix (LF) <?php
$fp = fopen('lock.txt', 'w');
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
/* Activate the LOCK_NB option on an LOCK_EX operation */
if(!flock($fp, LOCK_EX)) {
echo 'Unable to obtain lock';
exit(-1);
} else {
echo "Got the lock";
}
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Got lock within $time seconds\n";
/* ... */
fclose($fp);