2

How can my Perl program tell if is running under mod_perl?

I'm thinking along the lines of global variables or environment variables.

I am only bothered about mod_perl >= 2.

zgpmax
  • 2,777
  • 15
  • 22

2 Answers2

8

According to "Environment Variables" in the mod_perl user's guide:

$ENV{MOD_PERL} - is set to the mod_perl version the server is running under. e.g.:

  mod_perl/2.000002

If $ENV{MOD_PERL} doesn't exist, most likely you are not running under mod_perl.

  die "I refuse to work without mod_perl!" unless exists $ENV{MOD_PERL};

(see the above link for more information).

Community
  • 1
  • 1
ruakh
  • 175,680
  • 26
  • 273
  • 307
2

http://perl.apache.org/docs/2.0/user/coding/coding.html#Environment_Variables says that there will be an environment variable MOD_PERL, so you could test for that using the expression

exists $ENV{MOD_PERL}
zgpmax
  • 2,777
  • 15
  • 22