PHP high concurrent access to write files

WBOY
Release: 2016-07-25 08:46:08
Original
1141 people have browsed it
  1. function write ( $data )
  2. {
  3. $return = false;
  4. if ( $handle = @fopen ( 'error.txt','a+' ) )
  5. {
  6. $i=0;
  7. while ( !flock ( $handle,2 ) && $i++ < 3 )
  8. {
  9. usleep ( 500000 );
  10. }
  11. if ( $i < 3 && fwrite ( $handle,$data . "rn" ) )
  12. {
  13. flock ( $handle,3 );
  14. $return = true;
  15. }
  16. fclose ( $handle );
  17. }
  18. return $return;
  19. }
复制代码

php


Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!