Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm attempting to display an HTML page that contains a
flash file while another html page gets built in the
background from a few sql query's. I've gotten the fork
to work, however, I want the page that is being created
to replace the flash file that is running. What do I
have to change in order to get this to work?

My Code:
if ( $pid = fork() ) { ########## # Sets up the Unix and Oracle variables for the system ########## $ENV{ORACLE_HOME} = '/home/oracldwh/app/oracle/product/7.3.2'; $ENV{LD_LIBRARY_PATH} = '/home/oracldwh/app/oracle/product/7.3.2/l +ib'; # Database connection variables my $database = "**********"; my $username = "**********"; my $password = "**********"; my $html; ########## # Create initial portion of page with title and heading ########## $html .= header( -Refresh=> '0'; 'manager_selection_fork.cgi'); $html .= $query->start_html(-'title'=>'Asset Insight Manager Resou +rces', -BGCOLOR=>'#00CCFF'); ########## # Created the form portion ########## $html .= "<center>"; $html .= $query->startform({-method=>'post', -action=>'http://www3 +.syr.lmco.com/cgi-bin/asset/employee_list.cgi', -target=>'bottom'}); ########## # Connects to the database and runs the specified query ########## my $dbh = DBI->connect($database, $username, $password, 'Oracle') or die "can't connect to $database: $DBI::errstr"; my $sth = $dbh->prepare( q{ SELECT DISTINCT e1.emp_badge, e1.emp_name_last, e1.emp_nam +e_first, e1.emp_job_ttl FROM emp e1, emp e2 WHERE e1.emp_ssn = e2.mgr_ssn AND e1.emp_badge is not NULL ORDER by e1.emp_name_last }) or die "Can't prepare statement: $DBI::errstr"; my $rc = $sth->execute() or die "Can't execute statement: $DBI::errstr"; my @the_values; my %labels; ########## # Concatnates each returned row and pushes them into an array ########## while (my ($emp_badge, $emp_name_last, $emp_name_first, $emp_job_ +ttl) = $sth->fetchrow()) { $labels{"$emp_badge"} = join(' -- ', $emp_name_last, $emp_ +name_first, $emp_job_ttl); push(@the_values,$emp_badge); } ########## # Creates the dropdown box with the apropriate names and associati +ons ########## $html .= $query->popup_menu(-name=>'mgr_badge',-'values'=>\@the_va +lues,-labels=>\%labels); $html .= $query->submit(-value=>'Submit Selection'); $html .= "</center>"; $html .= end_html; ########## # Prints out the entire HTML Page as it was created above ########## print $html; # check for issue we may have had durring this little excursion warn $DBI::errstr if $DBI::err; ########## # This Ends the statement handle and closes the connection to the +database ########## $sth->finish; $dbh->disconnect; } ########## # The Child portion of the Fork ########## elsif ( defined( $pid ) ) { my $html2; $html2 .= header; $html2 .= $query->start_html(-'title'=>'Loading', -BGCOLOR=>'#00CCFF'); $html2 .= "<CENTER>"; $html2 .= "<!-- URL's used in the movie-->"; $html2 .= "<!-- text used in the movie-->"; $html2 .= "<!--L o a d i n g . --><OBJECT classid=\"clsid:D27CDB6E +-AE6D-11cf-96B8-444553540000\""; $html2 .= " codebase=\"http://download.macromedia.com/pub/shockwav +e/cabs/flash/swflash.cab#version=5,0,0,0\""; $html2 .= "WIDTH=250 HEIGHT=50>"; $html2 .= "<PARAM NAME=movie VALUE=\"http://www3.syr.lmco.com/ass +et/Loading.swf\"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor + VALUE=#FFFFFF> <EMBED src=\"Loading.swf\" quality=high bgcolor=#FFFF +FF WIDTH=250 HEIGHT=50 TYPE=\"application/x-shockwave-flash\" PLUGIN +SPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Pro +d_Version=ShockwaveFlash\"></EMBED>"; $html2 .= "</OBJECT>"; $html2 .= "</CENTER>"; $html2 .= end_html; print $html2; print "<br>\n"; #$END = time(); exit(); } #$END = time(); else { die( "Could not Fork" ); }

Replies are listed 'Best First'.
Re: Forking 2 html Pages
by merlyn (Sage) on Sep 18, 2001 at 19:00 UTC
Re: Forking 2 html Pages
by Cine (Friar) on Sep 18, 2001 at 18:03 UTC
    You dont.
    At least not the way you want it to work. There are two options:
    • Play with the contents header. Something like 'x-replace-mixed' and then ship out the two html files after eachother (thus no fork). This does not work on all browsers
    • Play with some javascript DHTML, to remove the flash when the rest is loaded ok. (no forking again). This will mean that the browser does not recieve a full page and there can be problems rendering it.


    T I M T O W T D I
Re: Forking 2 html Pages
by Rhandom (Curate) on Sep 18, 2001 at 19:25 UTC
    I haven't read merlyn's column but here is a quick simple option (simple is relative)...

    First, you could have the first page spit out a meta refresh tag that will bounce to the second page after a predetermined amount of time, if the second page isn't yet ready you could print another meta refresh. Alternately you could have a pipe open between the two processes, the forked one could could signal the parent, via the pipe, when it is ready, the parent would then send a javascript location bounce or a meta refresh to the browser (most browsers now will even let this occur at the bottom of a page, not just the headers) that will take you to the second page.

    Second, the forked process prepares the html and dumps it to a static file under an assumed session id. The meta refresh or javascript bounce will just need to pass the id along. When the browser hits the cgi again, the second page simply opens up and spits out the cached file.

    I haven't looked but I would imagine merlyn's solution does something similar.

    my @a=qw(random brilliant braindead); print $a[rand(@a)];