I have an application under Catalyst + FastCGI. And I want it to fork () to do some work in the background.
I used this code for simple CGI for a long time (and it worked):
defined(my $pid = fork) or die "Can't fork: $!";
if ($pid) {
exit 0;
}
die "Can't start a new session: $!" if setsid == -1;
close STDIN or die $!;
close STDOUT or die $!;
close STDERR or die $!;
I tried some variations of this in FastCGI, but without success. How should I fork in FastCGI?
Update: this is what I have now:
defined(my $pid = fork) or die "Can't fork: $!";
if ($pid) {
$c->stash->{message} = 'ok';
$c->detach($c->view('JSON'));
}
die "Can't start a new session: $!" if setsid == -1;
close STDIN or die $!;
close STDOUT or die $!;
close STDERR or die $!;
I am sending a request with an AJAX call and have the error "502 Bad Gateway" in the firebug console.
source
share