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;
}
posted on 2015-07-29 17:37 liuwenbohhh 阅读(197) 评论(0) 收藏 举报
浙公网安备 33010602011771号