Home  >  Article  >  php教程  >  php flock函数实例

php flock函数实例

WBOY
WBOYOriginal
2016-06-13 11:17:58784browse

由于 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);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn