I'm not sure if I didn't understood everything in this article of Watching long processes through CGI, but I don't care about refreshing and watching things like that. I just need to click a button -> start cgi script which starts system commands WITHOUT waiting for the end -> saying browser "hey I finished" (while the system commands are still running.What you probably want to do, is fork off the desired script, with SIG(CHLD) ignored, so it won't wait. Then, you close STDOUT and other filehandles in your cgi script, and the web server should close it off.
See Merlyn's Column 20
or this simpler example:
#!/usr/bin/perl
use warnings;
use strict;
$| = 1; # need either this or to explicitly flush stdout, etc.
# before forking
print "Content-type: text/plain\n\n";
print "Going to start the fork now\n";
if ( !defined(my $pid = fork())) {
print STDERR "fork error\n";
exit(1);
} elsif ($pid == 0) {
# child
close(STDOUT);close(STDIN);close(STDERR);
exec('./fork-long-process-test-process'); # lengthy processing
} else {
# parent
print "forked child \$pid= $pid\n";
exit 0;
}
|