By default, PerlSetupEnv is On, but PerlSetupEnv Off is another optimization you should consider.

mod_perl modifies the environment to make it appear as if the script were being called under the CGI protocol. For example, the $ENV{QUERY_STRING} environment variable is initialized with the contents of $r->args( ), and the value returned by $r->server_hostname( ) is put into $ENV{SERVER_NAME}.

But populating %ENV is expensive. Those who have moved to the mod_perl API no longer need this duplicated data and can improve performance by turning it off. Scripts using the module require PerlSetupEnv On because that module relies on the environment created by mod_cgi. This is yet another reason why we recommend using the Apache::Request module in preference to

Note that you can still set environment variables when PerlSetupEnv is Off. For example, say you use the following configuration:

PerlSetupEnv Off
PerlModule Apache::RegistryNG
<Location /perl>
    PerlSetEnv TEST hi
    SetHandler perl-script
    PerlHandler Apache::RegistryNG
    Options +ExecCGI

Now issue a request for the script shown in Example 11-2.

Example 11-2.

use Data::Dumper;
my $r = Apache->request( );
print Dumper \%ENV;

You should see something like this:

$VAR1 = {
          'GATEWAY_INTERFACE' => 'CGI-Perl/1.1',
          'MOD_PERL' => 'mod_perl/1.26',
          'PATH' => '/bin:/usr/bin:/usr... snipped ...',
          'TEST' => 'hi'

Note that we got the value of the TEST environment variable we set in httpd.conf.