This problem may be more of an Apache problem but I'm not sure. I hope this is not inappropriate to post this here.

I have a CGI script running on Perl/Apache/Linux that receives a GET request from another server that simply needs to respond with 200 OK or 500 HTTP Header if there is an error.

The system that is calling this script only waits about 10 -20 seconds (not changable). The problem I have is that I need to do some heavyweight processing. What I want to do is simply tell the client 200 OK "go away now" as the server calling our script would not recognize any other response or data anyway.

The problem is that the client is still hanging around until the script is completed.
I have disabled buffering and tried using the script as an nph script with no luck. The only way I can force the client to leave is by close(STDOUT), this feels like a big hack to me and I'm sure it will cause a problem at some point. Forking is not really an option either. I tried copying STDOUT, printing the header and closing STDOUT and restoring as follows with no luck,
#!/usr/bin/perl # @@@ THIS DOESN'T WORK @@@ require 5.001; $|=1; my $query = new CGI; open (OLDOUT, ">&STDOUT") or die "Couldn't dupe STDOUT!\n"; print $query->header(-status=>'200 OK'),"\n"; close(STDOUT); open (STDOUT,">&OLDOUT") or die "Couldn't restore STDOUT!\n"; close(OLDOUT); sleep(20); print "GO AWAY!;
The result is that the calling server will get the message "GO AWAY"
#!/usr/bin/perl # @@@ THIS DOES @@@ require 5.001; $|=1; my $query = new CGI; print $query->header(-status=>'200 OK'),"\n"; close(STDOUT); sleep(20); print "GO AWAY!;
The calling server will terminate immediatelly after the 200 OK.

Anyone else here ever have a similar problem or a solution for a more elegant fix?

Thanks.

In reply to RE: CGI Forcing client disconnect by shotgunefx

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.