FastCGI, Perl5, Environment variables and timezones

Jan Drehmer (Jan.X.Drehmer@telia.se)
Thu, 20 Feb 1997 09:45:48 +0100

Message-Id: <199702200845.JAA23163@linkoping.trab.se>
To: fastcgi-developers@OpenMarket.com
Subject: FastCGI, Perl5, Environment variables and timezones
Date: Thu, 20 Feb 1997 09:45:48 +0100
From: Jan Drehmer <Jan.X.Drehmer@telia.se>


Hi, FastCGI Developers/Users in the World!

I am using the following software:
 * FastCGI Dev Kit 1.5.1
 * sfio oct95
 * Perl5, 5.003_25
 * CGI.pm 2.30
 * FCGI.pm 0.26 - fixed so it links with FastCGI Dev kit 1.5.1 libraries

on the following hardware:
 * SGI, IRIX 6.2
 * SGI, IRIX 5.3
 * Sun SPARC, Solaris 2.5.1

and I have a problem.

The first time a FastCGI perl5 script runs, and I call localtime(), I get the
correct date and time according to the value of my TZ environment variable.
If I execute a command with the 'backtick' syntax, say:
  $result = `/bin/sh -c env`:
I get back the standard HTTP/CGI environment variables.

The second time (and all subsequent (spelling?)) times the FastCGI script is
run, the backtick command doesn't return anything of value and the call to
localtime() returns the date and time in the system default timezone (as if I
should execute a shell command without the TZ environment variable set.

On the Sun Sparc I get back a correct date and time because it has a way of
setting the system default timezone without being dependent of the TZ variable.
On the SGI I get the GMT timezone.

This is bugging me.

A FastCGI script written in C doesn't have the same problem, which makes me
think that it is a problem in Perl5, either in the Perl5 interpreter or in
the FCGI.pm module.

Have anybody else been experiencing this problem?
Do you have a suggestion for a solution?

For the time being, I start my FastCGI code by getting the localtime and the
gmtime, calculating the difference for the two times (in Sweden 3600 seconds)
and in my FCGI::accept loop I set a variable in the end of the loop to a
non-zero value.
This variable I check as well as if the $ENV{FCGI_ROLE} variable is defined
everytime I call localtime(). If the ENV variable is defined and the loop
variable is set, I add the time difference to the result I get from time() and
use this modified value when I call localtime().

So, if anyone has another, better, solution, I would be happy (an others with
me I think) to hear about it. I have searched the Web as well as Usenet and
the FastCGI developers mail archive but I have not seen anything there that
describes this problem.


Jan Drehmer, Telia Engineering AB, Linkoping, Sweden
Jan.X.Drehmer@telia.se