Is it a bad idea to fork under mod_perl2?

混江龙づ霸主 提交于 2019-12-06 07:21:41

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2554827/is-it-a-bad-idea-to-fork-under-mod-perl2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!