开发者

Stop multiple sessions accessing the same file simultaneously

开发者 https://www.devze.com 2023-01-03 04:28 出处:网络
Is it possible to lock a file to stop it being opened while GD library is accessing it? What I am lookin开发者_运维技巧g to achieve is similar to a database \'serialzable\' level of isolation... I w

Is it possible to lock a file to stop it being opened while GD library is accessing it?

What I am lookin开发者_运维技巧g to achieve is similar to a database 'serialzable' level of isolation... I want to ensure that only one session/user can access an image at a time to stop a 'dirty read'.

My application allows users to add an image of choice to a bigger image.

for example

  • the big image is empty
  • Raj & Janet upload their images
  • Raj's session opens the big image.
  • 1 ms later Janet's session opens the big image.
  • Raj's session add's his image and saves the big image
  • 1 ms later Janet's session adds his image and saves its version of the big image.
  • As a result Raj's image is not in the final image as Janet's version overwrote it.

I hope that makes it clear enough.


Check out flock. You can either lock the file you're working with, or create a "lock file" somewhere else in the filesystem which all your scripts check for.

0

精彩评论

暂无评论...
验证码 换一张
取 消