两个用户同时写入一个文件? (PHP/file_put_contents) [英] Two users write to a file at the same time? (PHP/file_put_contents)

查看:300
本文介绍了两个用户同时写入一个文件? (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆