Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Mod_Perl multiple timezones

by waldo22 (Novice)
on Mar 08, 2011 at 15:36 UTC ( [id://892032]=note: print w/replies, xml ) Need Help??


in reply to Re: Mod_Perl multiple timezones
in thread Mod_Perl multiple timezones

I realize that this thread is older than Perl itself, but it comes up very high in Google, so I thought I'd update.

The following works perfectly for me in Perl 5.10:

#!/usr/bin/perl use strict; use warnings; ### US Time Zones #my $time_zone = 'US/Alaska'; #my $time_zone = 'US/Aleutian'; #my $time_zone = 'US/Arizona'; #my $time_zone = 'US/Central'; my $time_zone = 'US/Eastern'; #my $time_zone = 'US/East-Indiana'; #my $time_zone = 'US/Hawaii'; #my $time_zone = 'US/Indiana-Starke'; #my $time_zone = 'US/Michigan'; #my $time_zone = 'US/Mountain'; #my $time_zone = 'US/Samoa'; #my $time_zone = 'US/Pacific'; ### set time zone for Perl to access with localtime ### can be any zone listed in /usr/share/zoneinfo and its subfolders $ENV{TZ} = $time_zone; print "System Time Zone from Perl is $ENV{TZ}\n"; my $timenow = localtime(time); print "Time from System is $timenow\n";

There was no need to use POSIX::tzset().

It works well from both the command line and from Apache2.

-Wes

Replies are listed 'Best First'.
Re^2: Mod_Perl multiple timezones
by jswalker (Initiate) on May 14, 2012 at 16:18 UTC
    One thing you may want to consider - I have been having some problems of my own with mod_perl resulting in my system running out of threads. This has forced me into researching threads in much more depth. One thing I have seen multiple times is that localtime() is not thread safe. While this doesn't seem to explain my issues it might explain yours. You can set the environment all you want, but if another thread comes along the TZ can get set to something else, even while localtime() is running, unless you have done something to lock access during your critical time between setting the TZ and getting a result from localtime().

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://892032]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found