flock.php
$fp=fopen('lock.txt','a');
if (flock($fp,LOCK_EX)){
fwrite($fp," HHHHHHHHHHHHHH".time()."\r\n");
}
?>
flock2.php
$fp=fopen('lock.txt','a');
if (flock($fp,LOCK_EX)){
fwrite($fp," GGGGGGGGGGGGGG".time()."\r\n");
}
?>
Doubt:
Why is the flock.php file locked with an exclusive lock, but the lock is not released and the fclose file is not closed. But when executing flock2.php file, it can still be written.
Isn’t the exclusive lock of the file lock unable to be written by other processes after it is locked? Can I write again only when the lock is released?
php is over after execution and the resources are released, and the lock will be released naturally
If you want to test, add an infinite loop to flock.php to ensure it never exits, and then execute flock2.php to see the effect