php高并发访问写文件
时间:2021-07-01 10:21:17
帮助过:3人阅读
- 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 . "\r\n" ) )
- {
- flock ( $handle,3 );
- $return = true;
- }
-
- fclose ( $handle );
- }
- return $return;
- }
|
php