Professional Web Applications Themes

forking and ending a CGI process - PERL Miscellaneous

Hi; I spent about 4 hours searching through newsgroups, faqs, and O'reilly books with various odd-smelling desert animals on the cover. I found that this question has been asked A LOT, but none of the answers worked for me. I'm posting this in hopes it will help someone else, and to solicit comments on why the other methods did not work and whether this is the best way. The problem: You are batching e-mails to a large number of subscribers, and you don't want the CGI script to wait until the mail process finishes before completing the page. Many people ...

  1. #1

    Default forking and ending a CGI process

    Hi;
    I spent about 4 hours searching through newsgroups, faqs, and O'reilly
    books with various odd-smelling desert animals on the cover. I found
    that this question has been asked A LOT, but none of the answers worked
    for me. I'm posting this in hopes it will help someone else, and to
    solicit comments on why the other methods did not work and whether this
    is the best way.

    The problem: You are batching e-mails to a large number of subscribers,
    and you don't want the CGI script to wait until the mail process
    finishes before completing the page.

    Many people wrote to just put
    $|=1;
    at the top of your script. I am using the Mail::Bulkmail module, so
    I tried this down near the end of the routine after the $bulk object had
    been defined.

    $|=1;
    print "";
    print qq(Thank you.... );
    $bulk->bulkmail() or die $bulk->error;

    and the script hesitated for 17 seconds before printing the thankyou
    statement, just as it did without the buffer change. Mail was delivered OK.

    Then I tried forking it like this:

    if (my $pid = fork) {
    print qq(Thank you.... );
    } else {
    die "cannot fork: $!" unless defined $pid;
    $bulk->bulkmail() or die $bulk->error;
    }

    No difference.

    Then I tried closing STDOUT

    $|=1;
    print "";
    if (my $pid = fork) {
    print qq(Thank you.... );
    close(STDOUT);close(STDERR);
    } else {
    die "cannot fork: $!" unless defined $pid;
    $bulk->bulkmail() or die $bulk->error;
    }

    That got instant results, but no mail was sent. I'm guessing
    that Apache terminated the process when STDOUT closed?

    Some people wrote to write the entire script to a new file and
    then use system() to call it, but this script needs to be portable,
    and some CGI wrappers don't allow system() calls or backticks.

    This is what finally worked:

    $|=1;
    print "";
    if (my $pid = fork) {
    print qq(Thank you.... );
    kill("KILLBUFFER"=>$$);
    } else {
    die "cannot fork: $!" unless defined $pid;
    $bulk->bulkmail() or die $bulk->error;
    }

    Comments or suggestions welcome.

    Rob






    Rob Young Guest

  2. #2

    Default Re: forking and ending a CGI process

    "Rob Young" <robyoung68> wrote in message
    news:Z2RZa.340165$o86.150401news1.central.cox.net ...
    > Hi;
    > I spent about 4 hours searching through newsgroups, faqs, and O'reilly
    > books with various odd-smelling desert animals on the cover. I found
    > that this question has been asked A LOT, but none of the answers worked
    > for me. I'm posting this in hopes it will help someone else, and to
    > solicit comments on why the other methods did not work and whether this
    > is the best way.
    >
    > The problem: You are batching e-mails to a large number of subscribers,
    > and you don't want the CGI script to wait until the mail process
    > finishes before completing the page.
    Use the "daemonzie" routine
    [url]http://www.perldoc.com/perl5.8.0/pod/perlipc.html[/url]


    gtoomey


    Gregory Toomey Guest

Similar Threads

  1. Forking Server
    By SRam in forum PERL Miscellaneous
    Replies: 2
    Last Post: September 18th, 12:16 AM
  2. Forking for performance?
    By ed in forum PERL Miscellaneous
    Replies: 6
    Last Post: August 27th, 06:38 AM
  3. Pre-forking SOAP servers
    By James Lavery in forum PERL Miscellaneous
    Replies: 2
    Last Post: July 7th, 07:04 AM
  4. Forking child process with WWW::Automate
    By Graham Wood in forum PERL Miscellaneous
    Replies: 3
    Last Post: June 27th, 02:38 PM
  5. Perl Forking Server Problems
    By Bryan Castillo in forum PERL Miscellaneous
    Replies: 0
    Last Post: June 26th, 04:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139