Created
June 7, 2018 07:35
-
-
Save niravmadariya/75f1ef563784e529bcd6475cd0142f7a to your computer and use it in GitHub Desktop.
Lock a file in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = fopen("test.txt","w+"); | |
// exclusive lock | |
if (flock($file,LOCK_EX)) | |
{ | |
fwrite($file,"Write something"); | |
// release lock | |
flock($file,LOCK_UN); | |
} | |
else | |
{ | |
echo "Error locking file!"; | |
} | |
fclose($file); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment