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

php flock函数实例

WBOY
WBOYoriginal
2016-06-13 11:17:58779parcourir

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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn