PHP high concurrent access to write files
Release: 2016-07-25 08:46:08
Original
1094 people have browsed it
- function write ( $data )
- {
- $return = false;
- if ( $handle = @fopen ( 'error.txt','a+' ) )
- {
- $i=0;
- while ( !flock ( $handle,2 ) && $i++ < 3 )
- {
- usleep ( 500000 );
- }
- if ( $i < 3 && fwrite ( $handle,$data . "rn" ) )
- {
- flock ( $handle,3 );
- $return = true;
- }
- fclose ( $handle );
- }
- return $return;
- }
复制代码
|
php
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 Articles by Author
-
2024-09-03 12:49:03
-
2024-09-03 12:48:09
-
2024-09-03 12:47:45
-
2024-09-03 12:47:22
-
2024-09-03 12:46:56
-
2024-09-03 12:46:55
-
2024-09-03 12:45:27
-
2024-09-03 12:45:09
-
2024-09-03 12:45:07
-
2024-09-03 12:42:35