Home >Backend Development >PHP Tutorial >Write files with high concurrency

Write files with high concurrency

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:02:03821browse
  1. function write($data) {
  2. $return = false;
  3. if ($handle = @fopen('error.txt','a+') ) {
  4. $i=0;
  5. while (!flock($handle,2) && $i++ < 3 ) {
  6. usleep(500000);
  7. }
  8. if ($i < 3 && fwrite($handle,$data . "rn")) {
  9. flock($handle,3);
  10. $return = true;
  11. }
  12. fclose($handle);
  13. }
  14. return $return;
  15. }
复制代码


Statement:
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