Home > Backend Development > PHP Tutorial > php flock function example_PHP tutorial

php flock function example_PHP tutorial

WBOY
Release: 2016-07-20 11:01:47
Original
1119 people have browsed it

Since flock() requires a file pointer, you may have to use a special lock file to protect access to files intended to be opened in write mode (adding "w" or "w+" to the fopen() function). ​

Since flock() requires a file pointer, you may have to use a special lock file to protect access to files intended to be opened in write mode (adding "w" or "w+" to 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);  fclose($fp);                                                                                                                                                                            
//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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template