由于 flock() 需要一个文件指针, 因此可能不得不用一个特殊的锁定文件来保护打算通过写模式打开的文件的访问(在 fopen() 函数中加入 "w" 或 "w+")。
由于 flock() 需要一个文件指针, 因此可能不得不用一个特殊的锁定文件来保护打算通过写模式打开的文件的访问(在 fopen() 函数中加入 "w" 或 "w+")。
fp = fopen("test.txt", 'ab'); //from the end
flock($fp, lock_ex); //lock the file for waiting...
fwrite($fp, 'just a test string.......'); //start writing...
flock($fp, lock_un); //release write lock
fclose($fp); //close the file读操作:
//read
$fp = fopen("test.txt", 'r');
flock($fp, lock_sh);
//read from the file.......
flock($fp, lock_un);
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号