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

Hi, Monks,

I want to access a script to run some routines, but I want to return to the page I call it from immediately, but continue running (it's running some tedious housekeeping during a registration). I have a way to do it, but it seems very awkward. Is there a better way. Without forking, that is ;)
#start of cgi #blah blah blah if(fork()) { exit 0; } else { close STDOUT; close STDIN; close STDERR; # do rest of work here }
I know there's no checking of results, etc., but that's not my worry at the moment. It's just a time consideration. With the code in the main registration page, people could get quite fed up waiting.

Oh, we're running vanilla cgi here, no mod-perl (not my choice!).

Replies are listed 'Best First'.
Re: script return control, but continue running?
by dave_the_m (Monsignor) on Jul 13, 2004 at 08:22 UTC
    You either have to fork, or pass a message to a separate (pre-existing) daemon somewhere to do the work on your behalf. Forking sounds like the easier of the two options.

    Dave.

Re: script return control, but continue running?
by bgreenlee (Friar) on Jul 13, 2004 at 08:37 UTC
    You could just have your cgi do:
    system('housekeeping.pl &');
    Perhaps not the most elegant solution, but it Gets the Job Done™.

    Brad

Re: script return control, but continue running?
by dfaure (Chaplain) on Jul 13, 2004 at 10:19 UTC

    You may find this node interesting.

    ____
    HTH, Dominique
    My two favorites:
    If the only tool you have is a hammer, you will see every problem as a nail. --Abraham Maslow
    Bien faire, et le faire savoir...

      If by interesting, you mean vaguely familiar, well, yes. I did search here and on CLPM, but didn't find anything. I'm continuing to doubt my searching skillZ. Thanks for the replies.

        The piece of code I cited would allow you to start a process and make it run like a daemon (aka init child), therefore made insensible to the death of invoking cgi. Isn't it that you wanted to get?

        ____
        HTH, Dominique
        My two favorites:
        If the only tool you have is a hammer, you will see every problem as a nail. --Abraham Maslow
        Bien faire, et le faire savoir...

•Re: script return control, but continue running?
by merlyn (Sage) on Jul 13, 2004 at 14:33 UTC