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:
  1. the '-M' test looks expensive if I put it in the FCGI loop and do it on every request
  2. what are the differences between 'require' and the suggested "do" here?, given that I do need to import some functions from that modules
  3. 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.