Apache-Reload
view release on metacpan or search on metacpan
lib/Apache2/Reload.pm view on Meta::CPAN
To reload modules only in certain directories (and their
subdirectories) add the following to the I<httpd.conf>:
PerlModule Apache2::Reload
PerlInitHandler Apache2::Reload
PerlSetVar ReloadDirectories "/tmp/project1 /tmp/project2"
You can further narrow the list of modules to be reloaded from the
chosen directories with C<ReloadModules> as in:
PerlModule Apache2::Reload
PerlInitHandler Apache2::Reload
PerlSetVar ReloadDirectories "/tmp/project1 /tmp/project2"
PerlSetVar ReloadAll Off
PerlSetVar ReloadModules "MyApache2::*"
In this configuration example only modules from the namespace
C<MyApache2::> found in the directories I</tmp/project1/> and
I</tmp/project2/> (and their subdirectories) will be reloaded.
=head2 Special "Touch" File
You can also declare a file, which when gets C<touch(1)>ed, causes the
reloads to be performed. For example if you set:
PerlSetVar ReloadTouchFile /tmp/reload_modules
and don't C<touch(1)> the file I</tmp/reload_modules>, the reloads
won't happen until you go to the command line and type:
% touch /tmp/reload_modules
When you do that, the modules that have been changed, will be
magically reloaded on the next request. This option works with any
mode described before.
=head2 Unregistering a module
In some cases, it might be necessary to explicitly stop reloading
a module.
Apache2::Reload->unregister_module('Some::Module');
But be careful, since unregistering a module in this way will only
do so for the current interpreter. This feature should be used with
care.
=head1 Performance Issues
This module is perfectly suited for a development environment. Though
it's possible that you would like to use it in a production
environment, since with C<Apache2::Reload> you don't have to restart
the server in order to reload changed modules during software
updates. Though this convenience comes at a price:
=over
=item *
If the "touch" file feature is used, C<Apache2::Reload> has to stat(2)
the touch file on each request, which adds a slight but most likely
insignificant overhead to response times. Otherwise C<Apache2::Reload>
will stat(2) each registered module or even worse--all modules in
C<%INC>, which will significantly slow everything down.
=item *
Once the child process reloads the modules, the memory used by these
modules is not shared with the parent process anymore. Therefore the
memory consumption may grow significantly.
=back
Therefore doing a full server stop and restart is probably a better
solution.
=head1 Debug
If you aren't sure whether the modules that are supposed to be
reloaded, are actually getting reloaded, turn the debug mode on:
PerlSetVar ReloadDebug On
=head1 Caveats
=head2 Problems With Reloading Modules Which Do Not Declare Their Package Name
If you modify modules, which don't declare their C<package>, and rely on
C<Apache2::Reload> to reload them, you may encounter problems: i.e.,
it'll appear as if the module wasn't reloaded when in fact it
was. This happens because when C<Apache2::Reload> C<require()>s such a
module all the global symbols end up in the C<Apache2::Reload>
namespace! So the module does get reloaded and you see the compile
time errors if there are any, but the symbols don't get imported to
the right namespace. Therefore the old version of the code is running.
=head2 Failing to Find a File to Reload
C<Apache2::Reload> uses C<%INC> to find the files on the filesystem. If
an entry for a certain filepath in C<%INC> is relative,
C<Apache2::Reload> will use C<@INC> to try to resolve that relative
path. Now remember that mod_perl freezes the value of C<@INC> at the
server startup, and you can modify it only for the duration of one
request when you need to load some module which is not in on of the
C<@INC> directories. So a module gets loaded, and registered in
C<%INC> with a relative path. Now when C<Apache2::Reload> tries to find
that module to check whether it has been modified, it can't find since
its directory is not in C<@INC>. So C<Apache2::Reload> will silently
skip that module.
You can enable the C<Debug|/Debug> mode to see what C<Apache2::Reload>
does behind the scenes.
=head2 Problems with Scripts Running with Registry Handlers that Cache the Code
The following problem is relevant only to registry handlers that cache
the compiled script. For example it concerns
C<L<ModPerl::Registry|docs::2.0::api::ModPerl::Registry>> but not
C<L<ModPerl::PerlRun|docs::2.0::api::ModPerl::PerlRun>>.
( run in 1.027 second using v1.01-cache-2.11-cpan-39bf76dae61 )