Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

11.5. PerlSetupEnv

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 CGI.pm 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 CGI.pm.

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
</Location>

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

Example 11-2. setupenvoff.pl

use Data::Dumper;
my $r = Apache->request( );
$r->send_http_header('text/plain');
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.



Copyright © 2003 O'Reilly & Associates. All rights reserved.


 
 
  Published courtesy of O'Reilly Design by Interspire