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

I have a general purpose Apache 2.0 running mod_perl2. It works great with a single perl web application running, however when I have more than one I occasionally see the error message "Can't locate object method foo...", and then the script dies.

All of these errors generally occur in a module I wrote called dataManager, which is a wrapper for DBI that encapsulates sql requests into methods. Each application has their own copy of this module, with different methods depending on what DB it needs to access. I am not using any exotic modules, all modules/scripts/etc use strict, and there is a total of 1 'our' variable in the whole mess. The apache server is using prefork and spawning fifty or so processes, and this issue always seems to occur after some time (i.e., not when apache is starting up).

How can I go about troubleshooting this? The problem only comes up with multiple applications sometimes, but the only solution I've found is to restart apache. Any ideas on what I can try?

Thanks!
  • Comment on Intermittant module problem with mod_perl

Replies are listed 'Best First'.
Re: Intermittant module problem with mod_perl
by tilly (Archbishop) on Jan 14, 2009 at 17:58 UTC
    Let me get this straight. You have multiple applications loaded in a single mod_perl process, each of which tries to load a slightly different module named dataManager?

    Well then I'd expect to see only one copy of dataManager loaded. Which means that one application will access another application's copy of dataManager and not find what it is looking for. If each application is moderately careful to load its own copy then you will only hit this when one process has actually served multiple applications, which takes time.

    The solution is to have different module names for each application so you don't get this inappropriate sharing. I would also, without seeing dataManager, suggest that you should take a look at some of the standard object-relational mappers out there because once you get through the learning curve, they likely are better for your future projects than your homegrown solution. The two most popular are DBIx::Class and Rose::DB.

Re: Intermittant module problem with mod_perl
by Rodster001 (Pilgrim) on Jan 14, 2009 at 18:12 UTC
    The simplest solution is to not use the same name for different modules. Apache/mod_perl doesn't (necessarily) know the difference of modules named the same thing. So, one process loads one version of the module and everything works great. But when another app uses that same process which loaded a "different version" earlier, it dies (as you explain).

    You might also include all the methods into one module which all apps can share.