Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a setup where nginx would try_files on the nedia direcotry and serve a static image file.

If it does not find it, will call the backend, pull the file from s3, create some DB entries and then copy the file to the media directory so further calls to that media file will be served by nginx.

Generating the file can take 5 seconds.

When a X new requests will come for this file and it's not generated yet, the backend will be called X times instead of just a single time. How can I avoid this problem and hold all requests until the file is ready ?

share|improve this question
up vote 1 down vote accepted

Create some kind of locking mechanism that inform other instances/threads that this file is currently processed and should wait. Easiest solution would be to write out a file in a temp directory with the required name and the let the script check for it's existence and go into a holding pattern if it exists.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.