I've got a CGI script which I need to call another perl script (myscript.pl) in the background (non-blocking) and then continue on displaying the HTML headers.
I use a $step variable, where $step=0 indicates to launch the Perl script and then $step automatically increments with each automatic page refresh. The page refresh is necessary to display real-time output.
My issue is that the call to myscript.pl seems to block and doesn't display any HTML when step=0 is passed as a CGI parameter - although the script is still launched. How can I correct this behavior to make the call non-blocking and display the HTML page? Thanks.
use warnings;
use strict;
use CGI;
use Proc::Background;
my $args = new CGI;
if(!defined $args->param('step'))
{
print $args->header;
blah blah blah
print $args->end_html;
exit;
}
if($args->param('step') == 0)
{
$step = 1;
my $proc1 = Proc::Background->new("perl","./myscript.pl","arg1","arg
+2");
}
elsif($args->param('step') > 0)
{
$step = $args->param('step');
$step ++;
}
print $args->header(-Refresh=>"5;url=http://localhost/cgi-bin/mycgi.pl
+?step=$step");
...
print <input type=\"hidden\" name=\"step\" value=\"$step\">";
print $args->end_html;
exit;