in reply to Re^2: Wait ... Loading ... message in Perl/CGI
in thread Wait ... Loading ... message in Perl/CGI

You have to learn about fork-ing and managing child processes. Here's some example code:

use POSIX qw(:sys_wait_h); sub doit { my $pid = fork(); unless (defined($pid)) { die "unable to fork: $!\n"; } if ($pid) { # parent # wait for child to finish and display waiting message my $start = time; while (1) { print "time spent waiting: ", time - $start, "\n"; last if (waitpid($pid, WNOHANG) > 0); sleep(2); } # child process has terminated # read results from file open(R, "<results-from-child-process"); while (<R>) { ... process results... }; close(R); } else { # child # perform time consuming computation here. ... # leave results in some file open(R, ">results-from-child-process"); print R ...; close(R); exit(0); } }

Replies are listed 'Best First'.
Re^4: Wait ... Loading ... message in Perl/CGI
by convenientstore (Pilgrim) on Jan 26, 2008 at 14:43 UTC
    thanks~ going to try this today and get back to you.