将在此处锁定锁定文件损坏吗?

问题描述 投票:0回答:1

在撰写文件时,flock()函数是否会在这种情况下防止文件损坏(如果两个进程碰巧尝试同时将数据写入文件)?

// Read the file data $file_data = "Stuff you want to add\n"; $file_data .= file_get_contents('foo.txt'); // Open the file for writing and get an exclusive lock $fp = fopen('foo.txt', 'w'); flock($fp, LOCK_EX); // Write the new data at the start of the file file_put_contents('foo.txt', $file_data); // Close and unlock the file fclose($fp);
    
php file
1个回答
0
投票
mengapasaya tidak bisa menggunakan文件

© www.soinside.com 2019 - 2025. All rights reserved.