function write_file($filename, $content)
{
$lock = $filename . '.lck';
$write_length = 0;
while(true) {
if( file_exists($lock) ) {
usleep(100);
} else {
touch($lock);
$write_length = file_put_contents($filename, $content, FILE_APPEND);
break;
}
}
if( file_exists($lock) ) {
unlink($lock);
}
return $write_length;
}
如何保证多个进程写文件成功
最新推荐文章于 2021-03-24 11:20:43 发布