Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Detached forking in a CGI script

by flexvault (Monsignor)
on Apr 29, 2016 at 18:22 UTC ( #1161897=note: print w/replies, xml ) Need Help??


in reply to Detached forking in a CGI script

xylose,

    I need the script to fork a child process and to get hold of the pid of this child, but to then not make the parent (the CGI process) wait for the child, and allow it to exit immediately.

A few years back and this process was easy, but today many of the web servers will not allow children to continue to run if the parent exits. I've gotten around this by using a continuous running Perl script that keeps checking a file for instructions on work to be passed to new forked script.

The cgi script locks the file, adds the work to be done to that file, and then closes (which unlocks also) the file and exits.

The continuous running script sees the new work and forks to do the required work. (Note: You can also use 'pre-forked' scripts to do this.)

Possibly the referenced module does something similar and may give a more complete solution than using your own 'fork'. Just because it uses 'fork' and 'exec' doesn't mean that there isn't a whole lot more logic necessary to provide independent processes to complete the work after the parent cgi script exits. YMMV

Regards...Ed

"Well done is better than well said." - Benjamin Franklin

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2020-09-19 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (114 votes). Check out past polls.

    Notices?