php多个进程写文件

多进程写文件
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;
}
原文地址:https://www.cnblogs.com/liuwenbohhh/p/4686617.html