#!/usr/bin/perl # This is asynctest.pl # Running under Apache 2.2/Linux. use strict; use warnings; use CGI; use IO::Handle; # Tried this: # STDOUT->autoflush(1); my $cgi=new CGI; unless ($cgi->param('a') eq 'foo') { my $pid=$cgi->param('pid'); print< foo

$pid

EOT exit; } else { # Tried this: $SIG{CHLD}='IGNORE'; if (my $pid=fork()) { # Redirect back to home screen, passing # the PID so we can keep an eye on it. print "Status: 302 Moved Temporarily\n"; print "Location: asynctest.pl?c=$pid\n\n"; # Tried this: # # my $old_fh=select(STDOUT); # $|=1; # select($old_fh); # And tried this: # # STDOUT->flush(); # And this: # # close STDOUT; # ...in varying combinations. # But this process always waits # for the sleep() in the other # process before sending the # redirect. exit; } else { close STDOUT; sleep(20); exit; } }