Confused about the exclusive lock of PHP file lock?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 13:15:13
0
1
534

flock.php
<?php

$fp=fopen('lock.txt','a');

if (flock($fp,LOCK_EX)){

  fwrite($fp," HHHHHHHHHHHHHH".time()."\r\n");

}

?>
flock2.php
<?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?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
大家讲道理

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!