I having an issue trying to get my head round 'forking'... I think! Basically I have a script executed over the Web from a form. It takes a filename as input, uploads it and then processes it. The actual processing takes an age so ideally I would like to upload the file, redirect to a web page, execute processing code in the background and finally send an email when it is all done. Currently I have something like:
open UPLOAD, ">$tmp_file"; while ( <$upload_file> ) { print UPLOAD; } close UPLOAD; print "Location: my_webpage_goes_here.htm\n\n"; my $pid = fork; $pid = 0 unless defined $pid; # be the kid if fork failed exit 0 if $pid; processing code on file goes here including subroutine to perform nslookup to verify email address &VerifyEmailAddress($email); my $mailprog = '/usr/sbin/sendmail'; open(MAIL,"|$mailprog -t"); sending email code goes here
What appears to happen is that the script does actually fork but it does not redirect to the webpage when I want it to and as it takes so long, it times out. First thing I want to fix is getting the webpage to display prior to the script forking. There are some other issues in that the forking process seems not to wait for the results of subroutines in the processing code section. I am processing email addresses and run an nslookup on addresses. I'm a little confused as to what might be happening after the forking statement? Maybe someone could shed some enlightened advice on this problem?

In reply to Redirecting to a webpage in a script before forking to code in a script by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.