两个用户同时写入一个文件? (PHP/file_put_contents) [英] Two users write to a file at the same time? (PHP/file_put_contents)
问题描述
如果我通过设置了FILE_APPEND
标志的file_put_contents
将数据写入文件,并且两个用户同时提交数据,那么是否会追加数据,或者是否有一个项目会被覆盖?
If I write data to a file via file_put_contents
with the FILE_APPEND
flag set and two users submit data at the same time, will it append regardless, or is there a chance one entry will be overwritten?
如果我设置了LOCK_EX
标志,第二个提交将等待第一个提交完成,还是在无法获得排他锁的情况下丢失数据?
If I set the LOCK_EX
flag, will the second submission wait for the first submission to complete, or is the data lost when an exclusive lock can't be obtained?
PHP通常如何处理?我正在运行5.2.9版.如果重要的话.
How does PHP generally handle that? I'm running version 5.2.9. if that matters.
谢谢, 瑞安
推荐答案
you could also check the flock function to implement proper locking (not based on the while / sleep trick)
这篇关于两个用户同时写入一个文件? (PHP/file_put_contents)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!