vit has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
Does anybody know a Perl solution for the following problem.
I am using Amazon WS with Load Balancer, which drops connection after 60 sec if there is no response from the back-end instance. My code (I use Perl/CGI) requires more than 60 sec to perform computations and start sending response.
Is there a simple solution to this problem?

Replies are listed 'Best First'.
Re: Response timeout solution
by Corion (Patriarch) on Jun 13, 2011 at 21:44 UTC

    If you need to have the complete response sent within 60 seconds, the first thing I'd do were to stop using CGI.

    If you have to just send something within 60 seconds, immediately print out some reply (let's assume 200 OK is good), and keep printing bogus headers until you have the response ready.

      If you need to have the complete response sent within 60 seconds, the first thing I'd do were to stop using CGI.

      CGI has nothing to do with that. It's my computations.

      If you have to just send something within 60 seconds, immediately print out some reply (let's assume 200 OK is good), and keep printing bogus headers until you have the response ready.

      This I think is what I probably need. Could you give me an example. Say, there is a loop where I do some computations. How can I push something back to the client in every iteration?
      What do you mean by printing bogus headers?

        I mean headers that contribute nothing to the response, just to show the client that "things are still going on". You might need to switch off buffering so that the client sees these headers and gets these as quickly as possible:

        Status: 200 OK X-Bogus-Header: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx X-Bogus-Header: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ... X-Bogus-Header: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Content-Type: text/html <html> <body> ...
Re: Response timeout solution
by BrowserUk (Patriarch) on Jun 14, 2011 at 16:09 UTC

    Based on no experience whatsoever, my suggestion would be to:

    1. Generate a unique url.
    2. Respond immediately with a screen notifying the user their file is being generated, with an estimate of the time it will take, and a refresh header that will connect to the unique url.
    3. Start a background process to create the file.
    4. When the refresh occurs, use the unique url to locate the file that you created and give the user a download link.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.