If Apache requires your program to exit to close out the browser, one possibility would be to close STDOUT and fork() and have the child do the work and the parent can exit when its done with the output.

If you ever move to mod_perl this will defeat the reduction in startup overhead since you will need to start a new script every time anyway. If it doesn't break mod_perl entirely by exiting early.

For mornal CGI this may work ok for you.

Update: Another thought. I have a system which needs some slowly changing data from another database so I have a daemon process that listens on a FIFO and my CGI script writes an information request to the FIFO and then goes on with its life.

The daemon process then reads the FIFO and gets the updates independant from the web process completely. The FIFO is checked in non blocking mode by the CGI for obvious reasons and the update request is just skipped by the CGI if the FIFO isn't ready to read data for any reason.

As a side benefit the web system can run 'offline' for a while completely transparent to the end users.


In reply to Re: Closing stdout on CGI early. by dga
in thread Closing stdout on CGI early. by tomazos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.