Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9272827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:57:19+00:00 2026-06-18T15:57:19+00:00

I have a HTTP Request Handler for mod_perl which needs to read an environment

  • 0

I have a HTTP Request Handler for mod_perl which needs to read an environment variable, from %ENV, at module load time. The environment variable is passed from the Apache config into mod_perl using the PerlSetEnv directive.

This worked fine, until we changed the Apache configuration to AutoLoad the handler at startup time, for performance reasons. When the module is AutoLoaded like this, thePerlSetEnv does not take effect at module load time, and the variable we need is only available from %ENV at request time inside the handler method.

Is there a way to continue using AutoLoad, but still set an environment variable in the Apache config which is available in Perl’s %ENV at module load time?

Minimal example:

Here’s a stripped down test-case to illustrate the problem.

The Apache config without autoload enabled:

PerlSwitches -I/home/day/modperl
<Location /perl>
    SetHandler modperl
    PerlSetEnv TEST_PERLSETENV 'Does it work?'
    PerlResponseHandler ModPerl::Test
    Allow from all
</Location>

Contents of /home/day/modperl/ModPerl/Test.pm:

package ModPerl::Test;

use strict;
use warnings;

use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const qw(OK);

my %ENV_AT_MODULE_LOAD = %ENV; # Take a copy

sub handler {
    my $r = shift;
    $r->content_type('text/plain');

    $r->print("ENV:\n");
    foreach my $key (sort keys %ENV) {
        $r->print("  $key: $ENV{$key}\n");
    }   

    $r->print("ENV_AT_MODULE_LOAD:\n");
    foreach my $key (sort keys %ENV_AT_MODULE_LOAD) {
        $r->print("  $key: $ENV_AT_MODULE_LOAD{$key}\n");
    }   

    return OK;
}   
1;

When localhost/perl is viewed in the browser, I see this:

ENV:
  MOD_PERL: mod_perl/2.0.5
  MOD_PERL_API_VERSION: 2
  PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  TEST_PERLSETENV: Does it work?
ENV_AT_MODULE_LOAD:
  MOD_PERL: mod_perl/2.0.5
  MOD_PERL_API_VERSION: 2
  PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  TEST_PERLSETENV: Does it work?

Hooray! TEST_PERLSETENV is available at module load time, as we want.

But when we change the Apache config to enable Autoload (by using + in the PerlResponseHandler like so):

    PerlResponseHandler +ModPerl::Test

I get the following output instead:

ENV:
  MOD_PERL: mod_perl/2.0.5
  MOD_PERL_API_VERSION: 2
  PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  TEST_PERLSETENV: Does it work?
ENV_AT_MODULE_LOAD:
  MOD_PERL: mod_perl/2.0.5
  MOD_PERL_API_VERSION: 2
  PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Boo! TEST_PERLSETENV is no longer available at module load time 🙁 How can I get it back while keeping the AutoLoad behaviour?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:57:20+00:00Added an answer on June 18, 2026 at 3:57 pm

    Argh, 30 seconds after posting this question, I found the answer. Thank you rubber duck.

    Move the PerlSetEnv to before the <Location> block which contains the PerlResponseHandler directive, and it works again!

    i.e. like this:

    PerlSwitches -I/home/dbarr/modperl
    PerlSetEnv TEST_PERLSETENV 'Does it work?'
    <Location /perl>
        SetHandler modperl
        PerlResponseHandler +ModPerl::Test
        Allow from all
    </Location>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTTP Request Dispatcher class that works most of the time, but
I need loging all HTTP request (from any application). I have Delphi 7.0. Anybody
I have developed a small WCF service which handles HTTP request. I want to
I have created a http handler fro my Jquery ajax call. which is working
I have long HTTP request ( generating large Excel file - about 60K records
I have set up several http request samplers in Jmeter that have either get
I have a problem with sending POST http request. It stops on (HttpWebResponse)request.GetResponse() and
I have a JMeter test plan with following http request samplers. Login Call some
I have a question about JSF and GET http request. How can I get
I have a relatively simple object with a method that makes an HTTP request.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.