another clue on Perl empty initial environment problem

Mark Brown (mbrown@OpenMarket.com)
Sun, 09 Jun 1996 22:03:58 -0400

Message-Id: <199606100204.WAA25291@breckenridge.openmarket.com>
To: fastcgi-developers@OpenMarket.com
Subject: another clue on Perl empty initial environment problem
Date: Sun, 09 Jun 1996 22:03:58 -0400
From: Mark Brown <mbrown@OpenMarket.com>


To review: For some reason we don't understand yet, if the initial
environment to a Perl script is empty, all the environment variables
associated with the first request are lost.

It turns out that if the Perl script enumerates %ENV using each
before calling FCGI::accept, all is well.  For instance,
in examples/tiny-perl-fcgi, changing

    use FCGI;

    $count = 0;
    while(FCGI::accept >= 0) {
    ...

to

    use FCGI;

    while (($ignore) = each %ENV) {
    }

    $count = 0;
    while(FCGI::accept >= 0) {
    ...

and suddenly the first request works like a charm.

(Actually, a single call to each %ENV seems to do it, but
my guess is that leaves the hash in a bad state should you
call each %ENV later for some more legitimate reason.)

My purpose in pointing this out is twofold:

    This work-around gives you a way to make your scripts more robust --
    not vulnerable to forgetting to configure an initial variable.

    Maybe this clue will help somebody fix the bug some day.

    --mark