php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22135 PHP confused by America/Los Angeles timezone
Submitted: 2003-02-09 00:56 UTC Modified: 2003-05-02 13:48 UTC
Votes:9
Avg. Score:2.2 ± 1.7
Reproduced:0 of 0 (0.0%)
From: vaughan at ucla dot edu Assigned:
Status: Closed Package: Date/time related
PHP Version: 4.2.3 OS: Linux (debian)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vaughan at ucla dot edu
New email:
PHP Version: OS:

 

 [2003-02-09 00:56 UTC] vaughan at ucla dot edu
<?
print("server timezone is: " . getenv('TZ') . "<br>\n");
 print("server time is: " . date("F j, Y, g:i a") . "<br>\n");
print("changing server time zone to US/Pacific....<br>\n");
putenv("TZ=US/Pacific");
 print("new server time is: " . date("F j, Y, g:i a") . "<br>\n");
print("new server timezone for this script is: " . getenv('TZ'));
?>

The above script gives the following output:

server timezone is: America/Los Angeles
server time is: February 9, 2003, 6:45 am
changing server time zone to US/Pacific....
new server time is: February 8, 2003, 10:45 pm
new server timezone for this script is: US/Pacific

the correct date and time in Los Angeles at the time of running the script is: February 8, 2003, 10:45 pm

The date command on the system gives the correct time and date.

/etc/timezone contains US/Pacific

setting environment variable TZ=US/Pacific before restarting apache has no effect on the above script. 

PHP configure line:

 './configure' '--with-mysql' '--with-apxs' '--with-config-file-path=/etc/php4/apache' '--enable-track-vars' '--enable-trans-sid' '--with-sybase=/usr/local/freetds' '--with-ldap' '--with-imap' '--with-curl=/usr' '--with-pgsql=/usr/include/postgresql' '--with-gd' '--with-xml' '--enable-cli'

Apache/1.3.26

Apache modules are: mod_php4, mod_ssl, mod_perl, mod_dav, mod_setenvif, mod_unique_id, mod_expires, mod_auth, mod_access, mod_rewrite, mod_alias, mod_userdir, mod_cgi, mod_dir, mod_autoindex, mod_status, mod_negotiation, mod_mime, mod_log_config, mod_macro, mod_so, http_core

This could be a problem with the underlying debian (2.2.19 kernel) system, but I thought I should report it.

Thank you.






Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-09 07:49 UTC] michael dot mauch at gmx dot de
Using tzselect on Debian leads to the assumption that your TZ variable should probably be "America/Los_Angeles" (with underscore). Can you test that, please?
 [2003-02-09 10:54 UTC] vaughan at ucla dot edu
Yes, tzselect suggests that TZ be set as 'America/Los_Angeles'.

I did this, using export TZ='America/Los_Angeles' and restarted apache.  It made no difference to the php script output. 

In other words, if php believes that the server timezone is 'America/Los_Angeles' it gives the incorrect time.  But if it believes that timezone is 'US/Pacific' it gives the correct time.  However, setting TZ to 'US/Pacific' also makes no difference to the script output.  So I'm wondering where PHP is picking up the timezone information from and how I can get it to believe that the timezone is 'US/Pacific' from startup.  Can I set that in php.ini?

(Also, there are two timezone commands on debian, tzselect and tzconfig.  tzconfig lets one choose either 'US/Pacific' or 'America/Los_Angeles' for the timezone, but neither makes a difference to this script).
 [2003-02-09 12:39 UTC] michael dot mauch at gmx dot de
"apachectl restart" does not pick up the new TZ environment variable. Did you try apachectl stop / apachectl start? I get the same results as you with TZ="America/Los Angeles", but "America/Los_Angeles" or "US/Pacific" work. As far as I know there's no php.ini setting that fiddles with timezones.
 [2003-02-09 13:54 UTC] vaughan at ucla dot edu
here's what I do, as root:

# export TZ='America/Los_Angeles'
# set | grep TZ
# TZ=America/Los_Angeles
# apachectl stop
/usr/sbin/apachectl stop: httpd stopped
# apachectl start
/usr/sbin/apachectl start: httpd started


output of the php script: 

server timezone is: America/Los Angeles
server time is: February 9, 2003, 7:51 pm
changing server time zone to US/Pacific....
new server time is: February 9, 2003, 11:51 am
new server timezone for this script is: US/Pacific

I notice that PHP does not pick up the underscore in "Los_Angeles".

What I wondered was whether there's a way to do the equivalent of putenv("TZ=US/Pacific") in php.ini?

However, I have just noticed that the time is wrong in OTRS running on the same server -- and it is a set of perl scripts.  So maybe this is not a PHP bug at all?
 [2003-02-09 16:49 UTC] michael dot mauch at gmx dot de
You don't have a

  SetEnv TZ "America/Los Angeles"

in your httpd.conf, do you? Or maybe TZ is fixed in your apachectl script?
 [2003-02-22 11:37 UTC] vaughan at ucla dot edu
no, TZ is not being set in httpd.conf nor in apachectl.

Experiment #1
What happens if we use putenv("TZ=US/Los_Angeles")?

the script:

<?
print("server timezone is: " . getenv('TZ') . "<br>\n");
print("server time is: " . date("F j, Y, g:i a") . "<br>\n");
print("changing server time zone to US/Los_Angeles....<br>\n");
putenv("TZ=US/Los_Angeles");
 print("new server time is: " . date("F j, Y, g:i a") . "<br>\n");
print("new server timezone for this script is: " . getenv('TZ'));
?>

here's the output, with the incorrect times:

server timezone is: America/Los Angeles
server time is: February 22, 2003, 5:01 pm
changing server time zone to US/Los_Angeles....
new server time is: February 22, 2003, 5:01 pm
new server timezone for this script is: US/Los_Angeles
output of date(T):US/Los_Angeles


Experiment # 2:

I also tried putting 

SetEnv US/Pacific

into httpd.conf.

this script:

 print("server timezone is: " . getenv('TZ') . "<br>\n");
 print("server time is: " . date("F j, Y, g:i a") . "<br>\n");
print("changing server time zone to US/Pacific....<br>\n");
putenv("TZ=US/Pacific");
 print("new server time is: " . date("F j, Y, g:i a") . "<br>\n");
print("new server timezone for this script is: " . getenv('TZ'));

produces this output:

server timezone is: US/Pacific
server time is: February 22, 2003, 5:29 pm
changing server time zone to US/Pacific....
new server time is: February 22, 2003, 9:29 am
new server timezone for this script is: US/Pacific
output of date(T):PST

In this case, PHP picks up the US/Pacific timezone from the environment, but gets the time wrong!

Experiment # 3

try with SetEnv = US/Los_Angeles in httpd.conf

same script as #2, produces bad output:

server timezone is: US/Los_Angeles
server time is: February 22, 2003, 5:34 pm
changing server time zone to US/Pacific....
new server time is: February 22, 2003, 9:34 am
new server timezone for this script is: US/Los_Angeles
output of date(T):PST

So it seems to be the case that the ONLY way to get PHP to have the correct time is to use putenv("TZ=US/Pacific") in a script.

Any other ideas?  Thanks for your help
 [2003-02-22 13:37 UTC] michael dot mauch at gmx dot de
I don't see a /usr/share/zoneinfo/US/Los_Angeles on Debian, only
America/Los_Angeles (and US/Pacific). So I suggest you try again with America/Los_Angeles.
 [2003-02-24 10:38 UTC] vaughan at ucla dot edu
You're right. I should have used "America/Los_Angeles".

results: experiment #1, using
 putenv("TZ=America/Los_Angeles");

php produces the correct time after this, but not before (that is, doesn't pick up TZ from the system).

experiment # 3, SetEnv TZ=America/Los_Angeles in httpd.conf
has no effect -- the time is still wrong until I use putenv with either "US/Pacific" or "America/Los_Angeles".
 [2003-02-25 02:26 UTC] sniper@php.net
SetEnv in httpd.conf has no effect on PHP.
You should set the timezone correctly before you _start_
apache, in the shell..


 [2003-02-25 02:27 UTC] sniper@php.net
As your first script mentioned, the output for
getenv('TZ') was "America/Los Angeles" which is wrong..

 [2003-02-25 13:25 UTC] vaughan at ucla dot edu
sniper@php.net wrote:
<snip>
You should set the timezone correctly before you _start_
apache, in the shell..</snip>

I tried that..see my posting below from 9 Feb 1:54pm. Even when TZ is set correctly in the shell to 'America/Los_Angeles' before starting apache, php's getenv('TZ') reports "America/Los Angeles" as the timezone. If I set TZ to 'US/Pacific' in the shell, stop and start apache, php still reports the timezone incorrectly as "America/Los Angeles".  So, if PHP does not seem to be picking up the timezone from the environment.  Again, the only way I can affect the timezone is using putenv(). 

Not sure where to go from here.  Perhaps pull from CVS and recompile?
 [2003-05-02 13:48 UTC] vaughan at ucla dot edu
I rebuilt php a while after my Feb 25th posting, and the problem mysteriously went away. Since I run the testing dist of Debian and update with apt regularly (almost daily), there's a good chance that some other package got changed and that's what fixed the problem.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Sep 10 13:01:27 2024 UTC