Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: CGI - run script without waiting

by zentara (Archbishop)
on Apr 15, 2014 at 15:24 UTC ( [id://1082354]=note: print w/replies, xml ) Need Help??


in reply to Re: CGI - run script without waiting
in thread CGI - run script without waiting

I'm not sure if I didn't understood everything in this article of Watching long processes through CGI, but I don't care about refreshing and watching things like that. I just need to click a button -> start cgi script which starts system commands WITHOUT waiting for the end -> saying browser "hey I finished" (while the system commands are still running.

What you probably want to do, is fork off the desired script, with SIG(CHLD) ignored, so it won't wait. Then, you close STDOUT and other filehandles in your cgi script, and the web server should close it off.

See Merlyn's Column 20

or this simpler example:

#!/usr/bin/perl use warnings; use strict; $| = 1; # need either this or to explicitly flush stdout, etc. # before forking print "Content-type: text/plain\n\n"; print "Going to start the fork now\n"; if ( !defined(my $pid = fork())) { print STDERR "fork error\n"; exit(1); } elsif ($pid == 0) { # child close(STDOUT);close(STDIN);close(STDERR); exec('./fork-long-process-test-process'); # lengthy processing } else { # parent print "forked child \$pid= $pid\n"; exit 0; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^3: CGI - run script without waiting
by Yaerox (Scribe) on Apr 15, 2014 at 15:59 UTC
    I'm actual not at work anymore that I could try this but tomorrow I'll try this for sure. I really appreciate your help. Thanks
Re^3: CGI - run script without waiting
by Yaerox (Scribe) on Apr 16, 2014 at 08:59 UTC

    I had some similar code but I must have done some mistakes. Your codes seems perfect on the first look. Did a few tests and always the exactly expected result.

    I'd now try to go on with my project getting this running. In case that I'll note something is not doing what expected, may I just reply here? :-)

    Thanks you Sir!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-29 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found