php “phpinfo():依赖系统的时区设置是不安全的......”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23920014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:03:07  来源:igfitidea点击:

"phpinfo(): It is not safe to rely on the system's timezone settings..."

phpdatedatetimetimezoneini

提问by Mark Satterfield

While running a php installation script for Blue.box (front end to FreeSwitch PBX), I get this error about a timezone failure.

在为 Blue.box(FreeSwitch PBX 的前端)运行 php 安装脚本时,我收到有关时区故障的错误消息。

Then I start digging. I'm not sure what is going on at this point. But here is what I have:

然后我开始挖掘。我不确定此时发生了什么。但这是我所拥有的:

I created an info.php file in my public_html directory that contains a single line:

我在 public_html 目录中创建了一个 info.php 文件,其中包含一行:

And I get this error and output

我得到这个错误和输出

Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are requiredto use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in /home/0default/public_html/info.php on line 1

警告:phpinfo():依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能是您拼错了时区标识符。我们在第 1 行的 /home/0default/public_html/info.php 中为“EDT/-4.0/DST”选择了“America/New_York”

date/time

     support    enabled
    "Olson" Timezone Database Version   0.system
    Timezone Database   internal
    Default timezone    America/New_York

    Directive   Local Value Master Value
    date.default_latitude   31.7667 31.7667
    date.default_longitude  35.2333 35.2333
    date.sunrise_zenith 90.583333   90.583333
    date.sunset_zenith  90.583333   90.583333
    date.timezone   America/New_York    America/New_York

I created a file /etc/php.d/timezone.ini with the following:

我创建了一个文件 /etc/php.d/timezone.ini ,内容如下:

[root@mercury php.d]# cat timezone.ini
; default time zone
date.timezone='America/New_York'
[root@mercury php.d]#

I'm able to change timezone to America/Los_Angeles (for example), and after apache reboot the "date.timezone" field changes correctly.

我可以将时区更改为 America/Los_Angeles(例如),并且在 apache 重新启动后,“date.timezone”字段会正确更改。

But I still get the error.

但我仍然收到错误。

Any ideas?

有任何想法吗?

--- Additional note ---

--- 附加说明 ---

If I change the /etc/php.d/timezone.ini file:

如果我更改 /etc/php.d/timezone.ini 文件:

[root@mercury php.d]# cat timezone.ini
; default time zone
date.timezone='America/Los_Angeles'

I can cause a change to the info.php output:

我可以改变 info.php 输出:

date

日期

Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are requiredto use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in /home/0default/public_html/info.php on line 1

警告:phpinfo():依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能是您拼错了时区标识符。我们在第 1 行的 /home/0default/public_html/info.php 中为“EDT/-4.0/DST”选择了“America/New_York”

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

Directive   Local Value Master Value
date.default_latitude   31.7667 31.7667
date.default_longitude  35.2333 35.2333
date.sunrise_zenith 90.583333   90.583333
date.sunset_zenith  90.583333   90.583333
date.timezone   America/Los_Angeles America/Los_Angeles

--- Additional note ---

--- 附加说明 ---

For those who are learning (as I am), several .ini files are loaded. In the info.php output:

对于那些正在学习的人(就像我一样),加载了几个 .ini 文件。在 info.php 输出中:

Configuration File (php.ini) Path   /etc
Loaded Configuration File   /home/0default/etc/php5/php.ini
Scan this dir for additional .ini files /etc/php.d
Additional .ini files parsed    /etc/php.d/curl.ini, /etc/php.d/dom.ini, /etc/php.d/fileinfo.ini, /etc/php.d/gd.ini, /etc/php.d/imap.ini, /etc/php.d/json.ini, /etc/php.d/mbstring.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/odbc.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_odbc.ini, /etc/php.d/pdo_pgsql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/pgsql.ini, /etc/php.d/phar.ini, /etc/php.d/snmp.ini, /etc/php.d/sqlite3.ini, /etc/php.d/timezone.ini, /etc/php.d/wddx.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlrpc.ini, /etc/php.d/xmlwriter.ini, /etc/php.d/xsl.ini, /etc/php.d/zip.ini

The first one loaded is /etc/php.ini, then the "loaded configuration file", then the "scan this dir" files.

第一个加载的是/etc/php.ini,然后是“加载的配置文件”,然后是“扫描此目录”文件。

So for example, one should be able to create a number of php web sites in different default timezones. Set the master default in /etc/php.ini, then allow each of the web sites to have a different time zone as identified in the "loaded..." section. Then, if one is concerned about any overrides, the master can again override with the /etc/php.d files.

因此,例如,您应该能够在不同的默认时区中创建多个 php 网站。在 /etc/php.ini 中设置主默认值,然后允许每个网站具有不同的时区,如“已加载...”部分所述。然后,如果您担心任何覆盖,master 可以再次使用 /etc/php.d 文件覆盖。

I've tried changing the "date.timezone" in each of the three locations, and successfully change the date.timezone as displayed by the info.php... but it does not modify the "Default timezone" value, which is the value that is causing the error.

我已经尝试在三个位置中的每个位置更改“date.timezone”,并成功更改了 info.php 显示的 date.timezone ......但它没有修改“默认时区”值,这是导致错误的值。

Another note, the .php script that I am running is actually Blue.box, a front end to FreeSwitch. So... I am hesitant in changing that .php script.

另请注意,我正在运行的 .php 脚本实际上是 Blue.box,它是 FreeSwitch 的前端。所以...我对更改该 .php 脚本犹豫不决。

回答by Ryan

You have 2 options:

您有 2 个选择:

  1. Call this function date_default_timezone_set()before using any date functions. E.g. date_default_timezone_set("America/New_York");.

  2. Edit the php.ini file usually located at /usr/local/php/php.iniand change the date.timezoneentry. Here is the list of supported timezones.

  1. 在使用任何日期函数之前调用此函数date_default_timezone_set()。例如date_default_timezone_set("America/New_York");

  2. 编辑通常位于 的 php.ini 文件/usr/local/php/php.ini并更改date.timezone条目。这是支持的时区列表

回答by kaushal

In my case I had update php.ini in two places. One was /etc/php5/apache2/php.iniand /etc/php5/cli/php.ini. You have to restart your apache and then it should work. Hope this helps!!!

就我而言,我在两个地方更新了 php.ini。一个是/etc/php5/apache2/php.ini/etc/php5/cli/php.ini。您必须重新启动 apache,然后它才能工作。希望这可以帮助!!!

回答by bosshida

I solved this problem by find which php.ini your server is using. First, you should make a page show phpinfo(), and you visit the page, you can see the normal infomation; Second, find "Loaded Configuration File" in the page, you should see what php.ini file your server is using. like:"/etc/php.ini"; Third, you edit the certain file in your server, like: date.timezone="Asia/Shanghai" then restart the server. Done. Good luck.

我通过查找您的服务器正在使用的 php.ini 解决了这个问题。首先,您应该使页面显示phpinfo(),并且您访问该页面,您可以看到正常的信息;其次,在页面中找到“加载的配置文件”,您应该可以看到您的服务器正在使用的php.ini文件。如:"/etc/php.ini"; 第三,您编辑服务器中的某个文件,例如:date.timezone="Asia/Shanghai" 然后重新启动服务器。完毕。祝你好运。