frederickmc
Programmer
I want to fork off a child process, and not have the parent wait for it to finish before printing a message in the browser. However, the message is not getting printed until the child process finishes.
Using Perl 5.8.0, Apache 2.0, RedHat Enterprise Linux 3.0
I have a simple script, below, which I am running in a browser for testing. I have tried numerous variations. Here are three. After the scripts I will show the results:
1. test.cgi
2. test2.cgi
3. test3.cgi
I am doing a tail -f on the error log to see the warns. On all of these, the warns come in the same, correct order. However, the browser page does not print until after the sleep. Here is the output of the error log, with the warns:
At gc4l.net there are links to the scripts. You can see that after clicking the link, the next page does not appear for 10 seconds.
Any suggestions or help would be appreciated.
Fred
Using Perl 5.8.0, Apache 2.0, RedHat Enterprise Linux 3.0
I have a simple script, below, which I am running in a browser for testing. I have tried numerous variations. Here are three. After the scripts I will show the results:
1. test.cgi
Code:
#!/usr/bin/perl
use strict;
$| = 1;
$SIG{CHLD} = 'IGNORE';
if (fork() == 0) {
warn "start child\n";
sleep 10;
warn "end child\n";
exit;
}
warn "start parent\n";
print "Content-type: text/html\n\n";
print "testing <a href=/index.html>Home</a>";
warn "end parent\n";
exit;
2. test2.cgi
Code:
#!/usr/bin/perl
use strict;
use Proc::Fork;
$| = 1;
$SIG{CHLD} = 'IGNORE';
parent {
warn "start parent\n";
print "Content-type: text/html\n\n";
print "testing <a href=/index.html>Home</a>";
warn "end parent\n";
exit;
}
child {
warn "start child\n";
sleep 10;
warn "end chile\n";
exit;
}
3. test3.cgi
Code:
#!/usr/bin/perl
use strict;
$| = 1;
$SIG{CHLD} = 'IGNORE';
defined (my $kid = fork()) or die "Cannot fork: $!\n";
if ($kid) {
warn "start parent\n";
print "Content-type: text/html\n\n";
print "testing <a href=/index.html>Home</a>";
warn "end parent\n";
exit;
} else {
warn "start child\n";
sleep 10;
warn "end child\n";
exit;
}
I am doing a tail -f on the error log to see the warns. On all of these, the warns come in the same, correct order. However, the browser page does not print until after the sleep. Here is the output of the error log, with the warns:
start child, referer: start parent, referer: end parent, referer: end child, referer:
At gc4l.net there are links to the scripts. You can see that after clicking the link, the next page does not appear for 10 seconds.
Any suggestions or help would be appreciated.
Fred