时间:2021-07-01 10:21:17 帮助过:3人阅读
[php] view plain copy
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;
}相关推荐:
php文件上传error的错误类型
以上就是PHP文件加锁确保多线程写入安全的详细内容,更多请关注Gxl网其它相关文章!