Two users write to a file at the same time? (PHP/file_put_contents)

时光怂恿深爱的人放手 提交于 2019-12-03 14:12:10

you could also check the flock function to implement proper locking (not based on the while / sleep trick)

If you set an exclusive file lock via LOCK_EX, the second script (time-wise) that attempts to write will simply return false from file_put_contents.

i.e.: It won't sit and wait until the file becomes available for writing.

As such, if so required you'll need to program in this behaviour yourself, perhaps by attempting to use file_put_contents a limited number of times (e.g.: 3) with a suitably sized usage of sleep between each attempt.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!