php.ini默认时区与date.timezone

Nig*_*awk 14 php timezone

当我date()在两个不同的服务器上使用PHP的功能时,我得到两个不同的结果,但两个服务器应该是相同的.

我检查了php.ini服务器#1上的文件,时间是正确的,它看起来如下:

date/time support                   enabled
"Olson" Timezone Database Version   0.system
Timezone Database                   internal
Default timezone                    America/Chicago

Directive        Local Value        Master Value
---------------------------------------------------
date.timezone    America/Chicago    America/Chicago
Run Code Online (Sandbox Code Playgroud)

我检查了服务器#2,它看起来如下:

date/time support                   enabled
"Olson" Timezone Database Version   0.system
Timezone Database                   internal
Default timezone                    UTC

Directive        Local Value        Master Value
---------------------------------------------------
date.timezone    America/Chicago    America/Chicago
Run Code Online (Sandbox Code Playgroud)

我看到的唯一区别是"默认时区"值.

两个服务器的日期/时间当前显示为:

Server #1: 10/23/2012 09:40:39
Server #2: 10/23/2012 14:40:39
Run Code Online (Sandbox Code Playgroud)

我确认两台服务器都使用php.ini位于内部的服务器,/etc并且我还搜索了两个网络目录,以查找时区可能被覆盖的任何位置:

grep -r "date_default_timezone_set" *
Run Code Online (Sandbox Code Playgroud)

But in that regard, they both contain the same files with the same settings.

Is "Default timezone" what's causing the 5h difference? If so, how do I correct it?

UPDATE

Loaded configuration files.

Server #2 contains two additional ini files:

/etc/php.d/snmp.ini
/etc/php.d/apc.ini
Run Code Online (Sandbox Code Playgroud)

php -i results.

Server #1:

date/time support => enabled
"Olson" Timezone Database Version => 0.system
Timezone Database => internal
Default timezone => America/Chicago

Directive => Local Value => Master Value
date.timezone => America/Chicago => America/Chicago
Run Code Online (Sandbox Code Playgroud)

Server #2:

date/time support => enabled
"Olson" Timezone Database Version => 0.system
Timezone Database => internal
Default timezone => America/Chicago

Directive => Local Value => Master Value
date.timezone => America/Chicago => America/Chicago
Run Code Online (Sandbox Code Playgroud)

What's interesting to note here is that for some reason the "Default timezone" does not match on server #2 when viewing it via php -i versus phpinfo() on a web page.

SOLUTION

The problem was with the CMS and its plugins. While server #1 and #2 had the same files and everything, it appears that plugins are not loaded in the same order on each server, which allowed the last plugin loaded to determine the timezone of my script.

原因php -iphpinfo不同之处在于,使用后date_default_timezone_set()会影响phpinfo()打印的内容.

修复是确保我在我需要进入的时区date_default_timezone_set().在我发布此问题之前对我不起作用的原因是因为我在从CMS加载一些必需文件之前声明了这一点,这可能会在那里再次设置时区.

Jas*_*ary 11

date()依赖于date.timezone INI设置.由于一个是芝加哥(CT),另一个是UTC,这是你的5小时差异.

我相信从PHP> 5.2开始你应该收到:

PHP警告:未知:依赖系统的时区设置是不安全的.您需要使用date.timezone设置或date_default_timezone_set()函数.

我建议您查看新的DateTime对象或使用SDC建议的UTC .


bra*_*dym 5

要检查的一些事项:

  1. 检查phpinfo()输出中的"已加载配置文件"值,以确保您正在更改正确的php.ini文件.(这不止一次地咬了我!)
  2. 查看phpinfo()输出时,请检查"附加.ini文件已解析"行,以查看在通过Web服务器运行时是否还有其他ini文件被解析.
  3. date.timezone可以通过ini_set函数设置.你有任何代码吗?由于auto_prepend ini设置,请务必检查可能正在运行的任何代码.