in reply to Issue with Running Long Processes thru CGI

Hi Sarah,

Just to analyse execution:

use CGI qw(:all delete_all escapeHTML); my $redirect_page = "display_page.cgi"; if (my $session = param('session')) { # returning to pick up session # # ...(2) redirect # my $data = $cache->get($session); if ( $data->[0] ){ # # ...(2a) flag set # } else{ # .... } elsif ( (my $slp = param('sleep')) eq 'sleep') { # ....(1) first invocation $cache->set($session, [0, ""]); # no data yet if (my $pid = fork) { # parent does # # ....(1a) fork: parent # print redirect(self_url()); } elsif (defined $pid) { # child does # # ....(1b) fork: child # $cache->set($session, [1, $buf]); exit 0; } else { # .... } } else { # display form # .... } # ....

When processing a cgi request with query parameter sleep eq 'sleep', you get to (2). A child process is forked, then two things happen concurrently:

The flag may, or may not get 'set' prior to get depending on timing (load, task size, scheduling etc..). This might explain why you are sometimes, but not consistantly getting to (2a).