I have three files in a directory as follows;
- A text file with some text: file.txt
- A simple script to lock the file: lock_file.php
<?php
$file = "./file.txt";
$fp = fopen($file, "a");
flock($fp, LOCK_EX);
echo $file . " locked!<br />";
?>
- A script to output the text from the file: read_file.php
<?php
$file = "./file.txt";
$text = file_get_contents($file);
echo $text;
?>
First I run lock_file.php and then I open read_file.php. I expected read_file.php not to work, because lock_file.php should have locked file.txt. However, when I run read_file.php it outputs the text from file.txt, as if file.txt has not been locked. Why is that?
Thanks!