Setting timezone not applying?

依然范特西╮ 提交于 2019-12-25 02:20:49

问题


With PHP 5.4 adding warnings to alert of timezone issues, this error is quite common:

Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are required to 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in somefile.php on line 42

Okay, fair enough. Adding date_default_timezone_set('UTC') is nice and simple, but I don't want to have to do this for every single script, especially when doing stuff on CLI.

So I added a line to my php.ini file:

date.timezone=UTC

And... it doesn't work. The warning still appears.

For debugging, I did this:

echo file_get_contents(php_ini_loaded_file());

And it outputs:

extension=./ext/php_gd2.dll
extension=./ext/php_oauth.dll
extension=./ext/php_curl.dll

date.timezone=UTC

The extension lines all work - I take them out and I can't use those functions, I put them in and I can. It's just date.timezone that's not taking. What am I doing wrong?


回答1:


  1. I've had a similar problem on OpenWRT - it turns out you need to properly set /etc/localtime

    Chek /usr/share/zoneinfo/ for available timezones (update system if needed) and choose your flavor (simply copy the right file).

  2. Another problem I've had is having different php.ini files for the different versions of php - cgi, fpm, cli, etc. - make sure you've added the date.timezone line in all the php.ini files you have on your system.

EDIT

You may have a second line in your php.ini file like this:

; some lines of variables
date.timezone = UTC
; more lines of variables
date.timezone = 
; even more lines

, that would effectively overwrite your date.timezone



来源:https://stackoverflow.com/questions/22760173/setting-timezone-not-applying

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!