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

php flock function example_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-20 11:01:47
Original
1181 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);

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template