Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a fast-cgi application that do some work at http://myapp.com/do?arg=x. The job may take a few minutes. So I want to keep redirecting the users to the same URL (with 307) until the job is done, and serve the results with a 200 OK. I would like to slow done the response rate, so that it takes the client 30s (for example) to receive a 307. Obviously, I don't want to do in the back-end because I need to handle other jobs. It is possible to tell nginx to insert a delay, or rate limit the response for a particular URL?

I've looked at limit_req, but I don't think it can be used to rate limit unique URLS (http://myapp.com/do?arg=x versus http://myapp.com/do?arg=y) but rather unique IP addresses.

share|improve this question

2 Answers 2

You might want to restructure your application to better handle the situation. I would have two scripts: one is the web page the user hits. The second is a back end script that dose the job.

Script two can be a daemon, or you can use non-blocking forking if your environment supports it from script one. Script one should initiate the job in script two, then push data to the user using something like EventStream (or WebSockets, although thats a major overkill here) updating them of the status. You can send a 200 or some other indication when your done.

share|improve this answer
    
Thanks for the idea. However, I'm targeting thin clients through an API rather than web browsers –  Julien Jan 4 '12 at 3:26
up vote 1 down vote accepted

I've settle for this solution:

  1. Send 307 with the headers:
    • Transfer-Encoding: chunked
    • Content-Length: X
    • Cache-Control: no-cache
    • Pragma: no-cache
    • write 1-byte chunk every second for X seconds
  2. 200 OK with the result
share|improve this answer

Your Answer

 
discard

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.