Calm has asked for the wisdom of the Perl Monks concerning the following question:

I’m new to perl and am working on a web application. I’ve just begun using modules, and had a very frustrating time trying to debug some issues. It seems the module is being cached by the webserver so updates aren’t available to the calling script until the webserver is stopped and restarted. That took awhile to figure out. A couple of questions:

1) Is there an easier way to clear out the webserver memory than stopping/restarting?
2) Is this the standard development cycle (make code change, stop webserver, restart webserver, test code change, repeat)?
3) Any suggestions for improving the way I’m doing this?

Thanks for your input.

Edit:
System info:
xampp v1.6.0a
Perl version: v5.8.8 built for MSWin32-x86-Multi-Thread (ActivePerl)
Web server: Apache
Update:
I've added the following lines to my httpd.conf:

PerlInitHandler Apache2::Reload PerlSetVar ReloadModules "Planning::*"

Now the module seems to reload, but only when I change the calling script in addition to the module. I.e., I can change the module and rerun the calling script and nothing changes, but if I change the calling script and the module, then the module will get reloaded. Is this the intended functionality or am I doing something wrong?

Replies are listed 'Best First'.
Re: Module updates require webserver restart?
by zer (Deacon) on May 02, 2007 at 18:10 UTC
    in mod_perl
    your httpd.conf should have:
    PerlInitHandler Apache::Reload PerlSetVar ReloadModules "Foo::* Bar::Foo" -or- PerlInitHandler Apache::Reload PerlSetVar ReloadTouchFile /usr/bin/perl/lib
    The first will reload on change the packages it contains allowing wild cards. The second will reload a directory if it has been touched.

    As non-mod_perl goes. I find it odd that you need to restart the web server to load the modules. It may tie into the mod_cgi.

    As well i may be making a dangerous assumption to believe you are using apache. Can you be more detailed with your problem

      Good information. Thank you.

      Can you be more detailed with your problem

      I've updated the question to include some of my system info. I'm apache on windows. My specific problem currently is that I don't know how to update the httpd.conf file to refresh my modules automatically. I added

      PerlInitHandler Apache2::Reload PerlSetVar ReloadTouchFile c:/apps/xampp/perl/lib

      to the very bottom of the file. I've got a test file where I change a single return value, but when I rerun the script calling it the return value doesn't change. This is just my test case, but I'd like to have my modules automatically refresh when I change them, at least during development. Simplified code example:

      package Planning::SysFunctions; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(fetchFY); @EXPORT_OK = qw(); use strict; use Time::localtime; use Apache2::Reload; sub fetchFY { # return localtime->year() - 100; return 53; }

      I run the script that calls this code, then I change the return value to 54, run the script again, but it still returns 53. If I stop and start my webserver, then it will return 54.

Re: Module updates require webserver restart?
by Fletch (Bishop) on May 02, 2007 at 16:27 UTC

    You haven't given enough details to be sure, but it sounds like you're running under mod_perl. mod_perl makes a persistent Perl interpreter per child httpd process and things get loaded once (more or less) at child start time. Then again that's why you use it (in production you bypass all that startup overhead after the first request).

    There are things like Apache::StatINC (but that's for mod_perl 1; I can't recall what the mp2 one is called) for making changes visible immediately at the cost of a few more system calls each request; that may be what you're interested in. Alternately if you're writing a CGI that's eventually going to run under Apache::Registry (or whatever the mp2 analogue is), configure things to run it as a real run-and-exit CGi during development and testing.

      I'm just running xampp (for Windows ver 1.6.0a) out of the box, which apparently means I'm running mod_perl. I didn't ask it to run mod_perl and I'm not sure how to turn it off (for dev only). Unfortunately, I know very little about mod_perl but I do know there are books and websites to help people like me who lack knowledge. I'll see if I can find some resources on the subject, as it appears I'm going to need to know something about it.

      Here is an error I was getting that alerted me to my mod_perl usage:
      Wed May 02 10:12:43 2007 error Undefined subroutine &ModPerl::ROOT::ModPerl::Registry::C_3a_Apps_xampp_htdocs_planning_projselect_2epl::login_new called at C:/Apps/xampp/htdocs/planning/projselect.pl line 51.\n

        You can either:

        a_ turn mod_perl off
        b_ configure mod_perl to use Apache::Reload

        there are 2 versions of modperl -- 1.3x and 2.0x -- they correspond to the apache 1.x and 2.x versions respectively.

        the mod_perl website is at: perl.apache.org
Re: Module updates require webserver restart?
by shmem (Chancellor) on May 02, 2007 at 18:10 UTC
    <plug mode="shameless">
    Apart from Apache::Reload, there's AutoReloader by yours_truly, which gives you fine control over your module's methods or subroutines on a per-subroutine basis. You just stuff your subs each into a file of it's own. After changing a sub file it will be reloaded. I'm working upon proper subclassing and inheritance (@ISA, inherited AUTOLOAD...)
    </plug>

    --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}
Re: Module updates require webserver restart?
by scorpio17 (Canon) on May 02, 2007 at 19:31 UTC
    This might just be your browser caching old script output. If you edit the script, you need to force a new page reload to get the new output, rather than the old (cached) output. You can do this with a "shift-reload" (hold down shift key while clicking reload button) - at least, this works in IE, Netscape, and Firefox.
      That is possible. One method of fixing this would be to use the POST method rather then the GET.

      mod_cgi has the docs for the module that executes your cgi. I havent seen anything on my server behave the way you described.

      Apache::Reload is a mod_perl thing, so i dont for see it working in your environment. If you see a " LoadModule mod_perl " in your httpd.conf then it is a good sign you are in mod perl but it doesnt sound like that

      The reason mod_perl would make a difference versus just the regular mod_cgi is that mod_perl constantly runs your script. Hence the modules are always stored in memory. Should you refresh the modules the state of the program restarts. With mod_cgi it starts a new instance of the script on each call. So theoretically it loads whatever state the modules are when they are called.