Prevent simultaneous access to a file by multiple scripts.
Source Code
$file = fopen("test.txt", "a+");
if (flock($file, LOCK_EX)) { // Exclusive lock
fwrite($file, "New contentn");
flock($file, LOCK_UN); // Release the lock
} else {
echo "Could not lock the file!";
}
fclose($file);