in reply to Getting Close and Cuddly with the sleep() function

as pointed out by extremely and roberto you should use fork() to spawn a new job and send your email.
you should also close STDIN and redirect STDOUT and STDERR
a little example:
#!/usr/bin/perl -wT use strict; use CGI; if(fork()) { my $q = new CGI; print $q->header(); print $q->start_html(); ## print your html here print $q->end_html; } else { close STDIN; open(STDOUT, ">>/tmp/yourscript.log") || die "Can't redirect stdou +t"; open(STDERR, ">&STDOUT") || die "Can't dup stdout"; #you have to log warnings somewhere... select(STDERR); $| = 1; # so you can see what's appening with tail... select(STDOUT); $| = 1; #your email stuff here... }
Update: Maybe you should also use a semaphore to prevent other istances of the script from running simultaneously...

Replies are listed 'Best First'.
RE: Re: Getting Close and Cuddly with the sleep() function
by skazat (Chaplain) on Nov 06, 2000 at 04:32 UTC

    what does:

    if(fork())

    do? does this fork the process if it can?

    is fork not allowed in some systems? this script is most likely going to be running on *nix, I'm very unknowing about how to make any forked processes. There are no easy to understand tutorial on it :)

    would it be better to have the web-based program actually gather the information, then pipe this info to another script that only does the mailing? this seems to be a somewhat the same idea to fork() to a child process to do the dirty work. Then would that script not fall into the timeouts of the cgi program?

    >>you should also close STDIN
    probably a good idea!

    Seems simple to just mail whoever the owner of the list is every time a batch goes out, or when the mailing is done to keep tabs.

    I'm stil a bit shaky on how to do this, does anyone else have any good advice? -justin simoni
    !skazat!

      if(fork()) doesn't mean "if fork worked": :)))
      it means if fork return a true value (the pid of the child process) then i'm the parent and i have to print my html else i'm the children (fork return 0) and i have to send the email. see "perldoc -f fork" for more info (and some hints on how andle errors)
      fork is a unix system call (see fork(2)) but recent versions of perl try to implement it on windows too
      for the second question: if you pipe your info to another script you have to wait for the second script to finish (unless you fork before the pipe :-)

        I see,

        wait, no, hold on. Where do you actually call the fork() function? Or how do you actually fork something into a child process? Thanks for the info on where to look for the correct documentation :) -justin simoni
        !skazat!