Stop multiple simultaneous access to the same file

Can I lock a file to stop it from opening when the GD library accesses it?

What I'm looking for is similar to the isolation level of the "serialzable" database ... I want only one session / user to access the image at a time to stop the dirty reading.

My application allows users to add a larger image.

, eg

  • large image is empty
  • Raj and Janet upload their images
  • The Raj Session opens a large image.
  • 1 ms later, Janet opens a large image.
  • Raj Session Adds Your Image and Saves a Large Image
  • 1 ms after the session, Janet adds his image and saves his version of a large image.
  • As a result, the Raj image is not in the final image as the Janet version overwritten it.

I hope this will be clear enough.

+3
source share
1 answer

Check out flock . You can lock the file you are working with, or create a โ€œlock fileโ€ elsewhere in the file system for which all your scripts are checked.

+2
source

Source: https://habr.com/ru/post/1749915/


All Articles