问题
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:
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).
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