I am currently using kill -9 to restart the fcgi process
Don't do that! Signal 9 is SIGKILL, and a process which receives this signal has no chance to
since it is not trappable, and AFAIK not propagated at all to the signalled process, but an instruction to the kernel to reap the process immediately (although the parent of the reaped process gets noified).
Use signals 1, 2, 3 or 15, not 9. Signal 9 is last resort only. Try
perl -le '$SIG{KILL} = sub {print "boom!"}; print $$; sleep;'
and kill that process from another shell with SIGKILL: no output.
But my questions keep:
- the '-M' test looks expensive if I put it in the FCGI loop and do it on every request
- what are the differences between 'require' and the suggested "do" here?, given that I do need to import some functions from that modules
- What should be considered differently between an OO-modules and non-OO-modules in this context..
Instead of using the rather obscure -M file test (which calls stat under the hood), I'd go with (stat $module)[9] i.e. mtime. Set up a $hash {$modulepath} = $timestamp at script start, preferrably using the key in %INC for easy comparison. Expensive? That's relative to what else your fcgi application is doing.
Also, you don't have to check the module files on every request. Set up a signal handler for e.g. SIGUSR1 (on the shell command line, kill -l will show you the available signals and their numbers) which sets a package global variable to some true value, and check that variable at every request. If it's true, reload the module (take care to undef $INC{'Some/Module.pm'} first) and clear the variable.
Differences between require and do:
See perlfaq8 for any bits that I missed here (or perldoc -q require).
For the suggestion-(2), I am not sure which SIG should I trap to handle the file change
Any but ALRM, CONT, ILL, ABORT, KILL, SEGV, ... I'd go with USR1 or USR2. But as stated above, I'd just set a variable in that signal handler, but not process the file immediately from somewhere inside your request processing where you could be using that module; instead delay that to the next request cycle.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: FastCGI and mod_perl's Apache::Reload equivalent???
by shmem
in thread FastCGI and mod_perl's Apache::Reload equivalent???
by lihao
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |