Home > php教程 > php手册 > php flock函数实例

php flock函数实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:17:58
Original
850 people have browsed it

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

source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template