Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Creating a background task from the web

by andy_7t (Novice)
on Jan 28, 2009 at 14:18 UTC ( [id://739573]=perlquestion: print w/replies, xml ) Need Help??

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

Hi,

I've got a perl script running through apache, which I want to call another program but run it in the background.

I've tried
system('/path/to/script');
system('/path/to/script &');
exec('as above');

These work, but the webpage just hangs waiting for the process to finish, or in this case, until Apache times out after 90 seconds (on my machine). How do I just fire off a background process? The background process is not a perl script by the way.

Thanks

  • Comment on Creating a background task from the web

Replies are listed 'Best First'.
Re: Creating a background task from the web
by Corion (Patriarch) on Jan 28, 2009 at 14:20 UTC
Re: Creating a background task from the web
by citromatik (Curate) on Jan 28, 2009 at 14:41 UTC
Re: Creating a background task from the web
by jethro (Monsignor) on Jan 28, 2009 at 14:56 UTC

    Your second example should work, to demonstrate:

    perl -e ' system("emacs &"); print "hello"; '

      This isn't a valid comparison, though. To compare it to a web application, you would have to run it as:

      perl -e 'system( "emacs &"); print "hello";'; exit

      And at this point, depending on a variety of factors (whether it's a local shell or an ssh connection to another host, what shell you are using, what command you ran) the exit may work, or it may sit and wait for the background command to finish, since STDOUT and STDERR are still connected.


      www.jasonkohles.com
      We're not surrounded, we're in a target-rich environment!
        You may have a point there. But shouldn't STDOUT and STDERR be inherited from the webserver and therefore the webserver not have to wait for a close.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://739573]
Approved by citromatik
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-24 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found