How to correctly set the server time?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

How to correctly set the server time?

Postby argl » 24. August 2010 23:22

I have xampp installed on a Vista laptop.
The time on the laptop is set correctly.
I am located on the US West Coast (Los Angeles).
My time zone is set to America/Los_Angeles in php.ini.

Yet when I use the following code to show the server date/time, the time seems to be 7 hours ahead:

echo date("l, F d, Y h:i" ,time());

What am I missing?
Thanks.
argl
 
Posts: 12
Joined: 24. August 2010 23:15

Re: How to correctly set the server time?

Postby argl » 25. August 2010 01:26

Aside from /php/php.ini, I also checked /mysql/bin/my.ini, and the time zone is set there correctly too.

Oddly, if I change the time zone in any of these files, it has absolutely no effect on the time. It still shows the same incorrect time.

What else do I need to do?
argl
 
Posts: 12
Joined: 24. August 2010 23:15

Re: How to correctly set the server time?

Postby JonB » 25. August 2010 01:48

:!:

try this tip: (read down the page a bit)

http://www.webcheatsheet.com/PHP/instal ... figure.php

At the moment you are displaying Zulu time (GMT/UT). Most PHP date functions were built to use the Unix timestamp for input, if its not present or cannot be ascertained I believe it uses the unadjusted system clock. (I have been wrong many, many times also). BIOS's (and timeservers) really keep GMT, and the OS overlay localizes it, that's why you pick a timezone when you do the Windows Setup. I'm going to do a sperymint later or tomorrow AM, right now I need to catch up on billing notes. Geeks need money for beer and cheap dates. :mrgreen:

Anyway - Good Luck
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: How to correctly set the server time?

Postby argl » 25. August 2010 01:59

Thanks for your reply. When I go to that link - do you mean setting the timezone in the php.ini? That is set correctly, and it is the php.ini that is loaded when I check phpinfo.

You are correct, it is UTC/GMT time. How can I get php to use the unix timestamp instead of the unadjusted system clock (Which seems to be a fallback function?)

Beer and cheap dates sounds good to me. :)
argl
 
Posts: 12
Joined: 24. August 2010 23:15

Re: How to correctly set the server time?

Postby JonB » 25. August 2010 05:04

well , sorta bad news -

"my" machine (this one is XP, I have a Win7 machine at work with XAMPP on it) returns the value correctly, using your code I pasted in.

The only time reference I can find in "my" php.ini is the date.timezone

date.timezone = "America/New_York"

Did you search the php.ini for multiple references? Some times adding a bit here or there to fix things, winds up with multiple values for the same parameter.

Does your phpinfo() page show the right path to the loaded php.ini?

I can check the Win 7 box tomorrow if this does not fix.

Good Luck
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: How to correctly set the server time?

Postby argl » 25. August 2010 07:14

That's odd. Could it be a Vista issue?

I checked the php.ini and only find one time reference as well:

date.timezone = "America/Los_Angeles"

There are no other references in the php.ini. And yes, phpinfo says "Loaded Configuration File: \xampp\php\php.ini", which is the correct location of the php.ini I checked. I also do not find any other php.ini's in all of xampp's subfolders.

Maybe something you should know: I installed Magento on this xampp server, and the blog extension picks up that wrong time when someone posts a comment, so that it shows up on the next day rather than on the day it was posted. Those who wrote the blog extension say it uses the server time when creating the comment. But I also checked Magento, and the locale is set to Los Angeles as well...

Thanks for your help. I guess somehow the issue lies with that fallback to the UTC time as you mentioned. Not sure what to check next though.
argl
 
Posts: 12
Joined: 24. August 2010 23:15

Re: How to correctly set the server time?

Postby Nobbie » 25. August 2010 10:22

Run a phpinfo() (instead of looking into php.ini) and search for "date.timezone". You will find a "Local Value" as well as a "Master Value". The Local Value overrides the Master Value. Maybe any installation (Magento?) sets a Local Value (can be done via .htaccess for example).

Check that.
Nobbie
 
Posts: 8780
Joined: 09. March 2008 13:04

Re: How to correctly set the server time?

Postby argl » 25. August 2010 18:17

I checked phpinfo, and both the local and master value are set to America/Los_Angeles. I also do not see anything in the .htaccess that refers to setting the date or time. And as mentioned, the locale set in Magento is America/Los_Angeles as well.
Argh, this is driving me nuts! Not that it is terribly important while developing, but if it does not work correctly on a test server, it probably won't work correctly once it is deployed, so I do want to fix this.

The code echo date("l, F d, Y h:i" ,time()); IS the most straight-forward to show the pure, unaltered server time, rather than the unadjusted system clock, is it? Or could the date/time formatting be messing with it? Can't imagine that.

I am tempted to move the whole installation to another machine running XP and see if it has the same issue there.
argl
 
Posts: 12
Joined: 24. August 2010 23:15

Re: How to correctly set the server time?

Postby BigWetDog » 25. August 2010 18:30

Does not specifiying the timestamp argument like this:
Code: Select all
echo date("l, F d, Y h:i");

produce a different result?
Last edited by BigWetDog on 25. August 2010 18:45, edited 1 time in total.
User avatar
BigWetDog
 
Posts: 148
Joined: 25. February 2010 15:54

Re: How to correctly set the server time?

Postby argl » 25. August 2010 18:41

Using echo date("l, F d, Y h:i"); gives me the same result. It says 05:40 (apparently meaning 5:40pm) when it is 10:40am my time.

If I add "e" and "T" to the echo function above, it confirms that it is using UTC time, and adding "O" and "Z" says there is 0 difference to GMT and a 0 offset from UTC.
Last edited by argl on 25. August 2010 18:59, edited 1 time in total.
argl
 
Posts: 12
Joined: 24. August 2010 23:15

Re: How to correctly set the server time?

Postby BigWetDog » 25. August 2010 18:54

what does
Code: Select all
echo date_default_timezone_get();
return?
User avatar
BigWetDog
 
Posts: 148
Joined: 25. February 2010 15:54

Re: How to correctly set the server time?

Postby argl » 25. August 2010 19:02

That returns "UTC".
argl
 
Posts: 12
Joined: 24. August 2010 23:15

Re: How to correctly set the server time?

Postby BigWetDog » 25. August 2010 19:05

is it possible that somewhere in the app
Code: Select all
date_default_timezone_set('UTC');
is being called?
User avatar
BigWetDog
 
Posts: 148
Joined: 25. February 2010 15:54

Re: How to correctly set the server time?

Postby BigWetDog » 25. August 2010 19:11

User avatar
BigWetDog
 
Posts: 148
Joined: 25. February 2010 15:54

Re: How to correctly set the server time?

Postby argl » 25. August 2010 19:28

Aha, getting a little closer. When I invoke date_default_timezone_set('America/Los_Angeles'); in the same script, it then echoes the correct time. Somehow it seems to ignore the timezone from the php.ini.

If I understand correctly, it first checks whether date_default_timezone_set was used and takes the time from that. If it does not find that, it checks the ini option.

This would mean that either, as you hinted at, that date_default_timezone_set has to be used somewhere that overrides the ini; or it somehow does not pick up the timezone from the ini correctly for whatever reason.

I scanned the entire xampp folder structure including Magento for any date_default_timezone_set calls right now. Found 2 instances of date_default_timezone_set('UTC'); but commenting them out and restarting the server had no effect on the timezone.

Interesting: when I run a plain php script right off the server, echo date_default_timezone_get(); shows the correct timezone! When I use echo date_default_timezone_get(); in the Magento script, it shows UTC. Meaning that it does seem to be a Magento issue. Damn, now I gotta dig deeper into that as well...
argl
 
Posts: 12
Joined: 24. August 2010 23:15

Next

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 45 guests