use File::Temp qw/tempfile/; use CGI; my $q = new CGI; # Get temp file before we fork my (undef, $tempname) = tempfile(OPEN => 0); my $pid = fork; if (not defined $pid) { print $q->header(-status=>'500 Server cutlery malfunction'); exit; } if ($pid) { # Parent. Redirect to display request. # XXX WARNING XXX - This implementation is # very insecure: better off creating a random # string and keying that in your database. print $q->redirect($BASE.'?display_id=' . $tempname); exit; } # ELSE, we're in the child. Run the long-lived command, # saving the result in $tempname. Do not attempt to # send any information directly to the browser. #### my $display_id = $q->param('display_id') // my_fatal_error_handler(); # Error if $display_id is undef open my $fh, '<', $display_id or my_fatal_error_handler(); print $q->header; print ''; # Page output here # Do not include the tag once you # have detected the command is finished, or redirect # to another page/script close $fh; unlink $display_id;