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

Good afternoon. I want to start a perl script on a remote web server using http. That is easy. But the problem is that I need the http connection to end before the remote server script is done. I don't need to wait for it to complete, just a reply that it is has started is fine. Let me illustrate: Local server script runs this code:
use LWP::Simple; get "http://remoteserver.com/startrunning.pl";
Remote web server with script startrunning.pl runs:
print "Content-type: text/html\n\n"; print "ok"; #need to kill the http connection here #start doing lots of things that are time consuming blah1(); blah2(); ...
I want to start the startrunning.pl script on the remote web server, but I can't have the local script that made the original http call waiting for the remote server to finish. I just need to trigger the startrunning.pl scrip and then drop the http connection. I hope this make sense and I hope there is a solution. Thank you.

Replies are listed 'Best First'.
Re: Trigger perl scrip remotely using http
by ikegami (Patriarch) on Mar 25, 2009 at 20:19 UTC
    #!/usr/bin/perl use strict; use warnings; $SIG{CHLD} = 'IGNORE'; if (fork()) { print "Content-type: text/html\n\n"; print "ok"; exit; } close(STDIN); close(STDOUT); close(STDERR); #start doing lots of things that are time consuming blah1(); blah2(); ...

    You can add error checking to fork and direct STDERR to a log file, but you get the idea.

    A better solution would provide feedback to the user. This article shows how it can be done.

      Just to clarify, this suggestion is to do a fork on the server so the parent process (the one you call over http) starts a child and then returns content to your client script immediately. The parent will then exit while the child happily continues forever.
      Yes, works perfectly. Thank you.