FAQ
If I have a cgi script that send text/plain what does the client see if I send
all the text at once but then don't exit for seconds because I'm doing some
background processing at my end? do they sit and spin around in circles?

Search Discussions

  • Tom Phoenix at Mar 25, 2006 at 3:41 pm

    On 3/25/06, Tom Allison wrote:

    If I have a cgi script that send text/plain what does the client see if I send
    all the text at once but then don't exit for seconds because I'm doing some
    background processing at my end? do they sit and spin around in circles?
    What happened when you tried it?

    If you want to do some background processing without tying up the
    client, you'll probably want your webserver to think that you're all
    finished. One way to do that is to fork a child process and let the
    parent quit. If the child then closes the output filehandles STDOUT
    and STDERR, the webserver should conclude that the CGI program has
    finished, even though the child process is still running.

    Instead of simply closing the output filehandles, you could reopen
    them, with the output going to a file (or even /dev/null). In Perl,
    it's generally better to reopen the standard filehandles like that
    rather than closing them, so that new filehandles will be properly
    numbered internally. The important thing is that the webserver sees
    that nobody is writing to it any longer, since the filehandles are
    closed, so it can reply to the remote user.

    Hope this helps!

    --Tom Phoenix
    Stonehenge Perl Training
  • Koms Bomb at Mar 26, 2006 at 9:17 am

    If I have a cgi script that send text/plain what does the client see if I send
    all the text at once but then don't exit for seconds because I'm doing some
    background processing at my end? do they sit and spin around in
    circles?

    Don't hang the request for long time, otherwise, the client maybe time out
    and the user sees a failure page.
  • Tom Allison at Mar 26, 2006 at 3:32 pm

    Koms Bomb wrote:
    If I have a cgi script that send text/plain what does the client
    see if I send
    all the text at once but then don't exit for seconds because I'm
    doing some
    background processing at my end? do they sit and spin around in
    circles?


    Don't hang the request for long time, otherwise, the client maybe time out
    and the user sees a failure page.
    I shouldn't. I'm just trying to address what amounts to a 1 second delay in
    backend work. I don't think it's enough time to merit forking but I was curious
    what the client would see.

    I'll have to write some scripts to mimic this.
  • M. Kristall at Apr 10, 2006 at 10:48 pm
    Closing STDOUT should be good enough for the server. Alternatively, if
    you know how big the content you are sending is, you can send a
    Content-Length header, and assuming the client doesn't ignore that (it
    shouldn't), the client will say the page is done when it is.

    It might make more sense to run a separate process to do your background
    work because the server (the particular thread or instance of it) may
    wait for your program to exit before accepting new connections.

    Tom Allison wrote:
    If I have a cgi script that send text/plain what does the client see if
    I send all the text at once but then don't exit for seconds because I'm
    doing some background processing at my end? do they sit and spin around
    in circles?

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedMar 25, '06 at 2:26p
activeApr 10, '06 at 10:48p
posts5
users4
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase