Because Flock () requires a file pointer, you may have to use a special lock file to protect access to the files that you intend to open through write mode (add "w" or "w+" in the fopen () function).
Because Flock () requires a file pointer, you may have to use a special lock file to protect access to the files that you intend to open through write mode (add "w" or "w+" in the fopen () function).
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 operation:
Read
$fp = fopen ("test.txt", ' R ');
Flock ($FP, lock_sh);
Read from the file .....
Flock ($FP, lock_un);
!--? PHP Tutorial
$fp = fopen ("/tmp/lock.txt", "w+");
If (Flock ($FP, LOCK_EX)) {//For exclusive locking
fwrite ($fp, "write Something Heren"),
flock ($fp, lock_un);//Interpretation Put lock
} else {
echo "couldn& #39; t lock the file!";
}
Fclose ($fp);
? >
flock () cannot be used for NFS and some other network file systems. See the documentation for your operating system for more information. The
Flock () is implemented at the process level in some operating systems. When using a multithreaded server API (such as ISAPI), you may not be able to rely on flock () to protect files, because PHP scripts running on other parallel threads in the same server instance can handle the file
< span id= "url" itemprop= "url" >http://www.bkjia.com/phpjc/445408.html www.bkjia.com true http://www.bkjia.com/phpjc/445408.html techarticle because flock () requires a file pointer, Therefore, you may have to use a special lock file to protect access to files that you intend to open through write mode (in the fopen () function, add W or ...
& #xe63a;-->