Karen Andrien wrote:
Hi there,

I'm researching how to implement timezones in PHP, and found a wealth
of information on the subject.  For Linux users, it all seems to boil
down to one recommendation:  use the putenv("TZ=xxx") statement.

The software I'm working on needs to be able to display a grid of hours
for the current date, for a user in any timezone.  (The timezone can be
passed to the script as, e.g., $_COOKIE['TZ'] = 'America/Vancouver'.) So far so good. putenv() will change the timezone environment variable
and the operating system will take care of the rest transparently.

However, I haven't been able to find any information on the scope of
the putenv() statement.  What happens if users from Vancouver and
Toronto log on at the same time?

The PHP documentation says putenv() applies "for the current request"
only, but several users on the documentation page disagree.  They claim
that putenv() has changed the time zone for both the current request
and other future requests at random.

Can anybody clarify the putenv() scope for me?

My best guess is that the scope is PHP request-level, but Apache
session-level.  When putenv() is called, it applies to the current
Apache session, and all future connections which happen to arrive on
the same connection.  If this is true, I would simply have to restore
putenv() to the default at the end of the script.

seems like a more than reasonable assessment. regardless of what it is
supposed to do there apparently seems to be problems for some people,
sometimes on some kinds of systems - given that fact you would be best off
restoring the ENV to the original state at the end of each script
(you might consider an auto_append_file directive to take care of such stuff.)


But I don't want to test this on my system in case I'm wrong.  I don't
have a separate development machine.

nothing a quick 'apachectl graceful' won't fix :-)


Here are all the possibilities I've thought of:
   * Current PHP request only
   * Current PHP session only (including future requests)
   * Current PHP process only (including random future requests)

this would seemingly point to the ENV var being set for the given apache
children process - every request is handled by an arbitrary child process
and there will be a number of them hanging around waiting to handle a
request at any given time (dependent on your apache conf.) and a child process
is usually set up to handle a given number of reuqest before being killed
off - that would more than account for the 'random' part.

   * All of PHP (including other current requests)

   * Current Apache request only
   * Current Apache connection only (including random future requests)
   * All of Apache (including other current connections)

   * All of Linux (this is such a bad idea that I'm sure it's wrong)

Thanks very much,
Karen Andrien


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

--
PHP Internationalization Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to