views:

126

answers:

2

Are there any counterindications to fork under mod_perl2? Should one use another way to run background process under mod_perl2?

+3  A: 

I usually use a cleanup handler to run anything that needs to happen after the HTTP request is complete:

$r->push_handlers( PerlCleanupHandler => sub { print "I'm doing stuff!" } );

If you really need to do a fork, you shouldn't do it the regular way, because your forked process will interfere with various resources that Apache needs, like file descriptors and sockets, and it's very hard to handle all this correctly. Instead, try out Apache2::SubProcess.

friedo
Is it OK to run a daemon process with `PerlCleanupHandler`? I mean, a process with unlimited execution time?
codeholic
If you're starting a daemon you definitely want to use a sub-process. Otherwise you'd tie up an Apache thread which would be stuck in its cleanup phase forever.
friedo
Do you know if `Apache2::SubProcess` work together with `ModPerl::Registry`? Because I cannot make it run http://stackoverflow.com/questions/2559093/why-doesnt-apache2subprocess-spawn-my-subprocess
codeholic
A: 

You might consider running a reverse proxy. You have heavyweight processes on the back end that handle resource intensive stuff, and lightweight processes on the front to handle easy stuff such as returning static content. Your heavy processes don't tie up the easy stuff because you don't have to wait for them to finish whatever they are doing.

brian d foy
I need to pass some data from front-end to back-end securely. And I must be sure that data go in the right direction. Hence code checksum control etc.
codeholic