Jim Morrison [Mailing-Lists] wrote:
Hello,

Not sure if this isn't slightly OT, but wonder if someone can help..

It seems on topic to me...


I have a piece of one of my mod_perl apps that potentially takes quite a
while to complete. What I would like to do is to get Apache/mod_perl to
start a second process which would do the work, return a page to the
user, and get on with the next thing..

Using fork is expensive. It will use up as much memory as the current child is already using, so you might as well just use the current child to finished the processing.


What I usually do in this situation is to register a cleanup handler that does the actual processing. This means the child is locked up until the processing is complete, but the client is free to continue browsing since the cleanup phase runs after the request phase has already finished.

Just add something like the following to your code.

$request->register_cleanup(sub { # Do your heavy processing here });

If you are going to have a lot of clients using this page simultaneously, then you will need to make sure that all your child processes aren't taken up by these long running programs. Otherwise any new requests will block until a child process is avaliable.

Along with the other suggestions that have already been made, you should have some options to look into now...

Cheers,

Cees




-- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html



Reply via email to