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

Hi,

I'm trying to debug some Perl code in a mod_perl environment. I'll try to get to the root of my issue:

When I start apache I can see the values of $ENV{MOD_PERL} and $ENV{MOD_PERL_API_VERSION}. I see this by doing something (e.g. go to a URL) and print to my error log the values of MOD_PERL and and MOD_PERL_API_VERSION. When I go back to the URL and get the same Apache PID those two ENV variables are gone (I still see everything else in %ENV). I am searching through my sea of code and CPAN modules and I am having trouble determining what is removing the environment variables. Has anyone experienced something like this before?

Regarding why this matters, certain CPAN modules such as XMLRPC::Transport::HTTP look for the MOD_PERL_API_VERSION.

If you could point me in the right direction it would be much appreciated.

Replies are listed 'Best First'.
Re: MOD_PERL ENV variable unsetting?
by NetWallah (Canon) on Sep 18, 2013 at 03:20 UTC
    If $ENV{MOD_PERL} doesn't exist, it is possible that the second invocation of the URL is not running under MOD_PERL.

    Maybe MOD_PERL crashed ? Check your syslog and Apache error.log. (This is just a wild guess).

                 My goal ... to kill off the slow brain cells that are holding me back from synergizing my knowledge of vertically integrated mobile platforms in local cloud-based content management system datafication.

      That's an interesting question. I don't see anything in syslog or apache error log mentioning mod_perl (other than in the apache log on startup). Is there anything else I can look at?

        Well here's what I noticed - If I set any $ENV{anything} on Apache startup in Perl code, it gets wiped out after the first use per PID just like the MOD_PERL environment variables, but if I use SetEnv it doesn't.

        I don't know what/why they are being removed -- perhaps it's even in some .so. Regardless, my workaround is to add:

        SetEnv MOD_PERL_API_VERSION 2
        SetEnv MOD_PERL 'mod_perl/2.0.6-rc2'

        to my httpd.conf.

        Thanks.

Re: MOD_PERL ENV variable unsetting?
by Anonymous Monk on Sep 18, 2013 at 03:17 UTC
    Well, I would look to my code and grep for [*%$@]ENV or ack for [*%\@\$]ENV\b

      I grep'd for it searching through my own code and the CPAN modules I have on my server. It's certainly possible I'm missing something, but I don't see it. I mostly wanted to see if it's expected behavior for the MOD_PERL ENV variables to go away (which it sounds like it isn't).