Skip to content

Instantly share code, notes, and snippets.

@ryanseys
Created December 17, 2014 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanseys/c30633d18917ff3a5458 to your computer and use it in GitHub Desktop.
Save ryanseys/c30633d18917ff3a5458 to your computer and use it in GitHub Desktop.
<?php
// file_put_contents("file1.txt", "this is a message", FILE_APPEND | LOCK_EX);
$fp = fopen("file1.txt", "w+");
/* open the file */
if (flock($fp, LOCK_EX | LOCK_NB)) {
fwrite($fp, "another message");
sleep(3); // sleep for 3 seconds
flock($fp, LOCK_UN); // unlock
fclose($fp);
echo "Completed.";
} else {
echo "Lock not set.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment