Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Can I have a Perl script, initiated from a browser, fork itself, and not wait for the child to end?

by dave_the_m (Monsignor)
on Apr 07, 2022 at 08:24 UTC ( [id://11142787]=note: print w/replies, xml ) Need Help??


in reply to Can I have a Perl script, initiated from a browser, fork itself, and not wait for the child to end?

The direct answer to your question is that the filehandles which form the connection to the web client get duplicated in the child, so the connection doesn't get closed until both the parent and child have closed the filehandles. So normally the parent would fork, the child would immediately close any filehandles it shares with the parent, then go off and do its thing. In the meantime the parent handles doing any HTML output then quits.

Note that you show both the parent and child outputting the headers, which is wrong.

But more generally this arrangement is likely to be a bad idea. It's very easy for someone to maliciously or inadvertently send many short requests to the web server, which results in thousands of long-running forked processes vying for memory and CPU.

Dave.

  • Comment on Re: Can I have a Perl script, initiated from a browser, fork itself, and not wait for the child to end?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found