2015年7月10日金曜日

PHPのdateのdefalt timezone set Warnig

PHPでのDate Warning


PHP環境を構築してdate関係の関数を使うとこんなふうな警告を受けることが有ります。

 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.

これは書いてあるとおり、date.timezoneの設定がされていないということです。システムから読み込んで使う時刻は安全でないので、php.iniに運用する場所のtimezoneを設定してください。

phpinfo()関数でphp.iniのパスとdate.timezoneが設定されているか確認して下さい。


; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
; date.timezone =

になっている部分を

; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = "Asia/Tokyo"

に変えてサーバーをrestart

反映されて警告が出なければ成功です。

CLIでもDate Warningが出る場合


CLIの呼び出すPHP環境が違うものを使っているかもしれません。
CLIの環境は以下のコマンドで確かめられます。

# php --ini

Loaded Configuration File:  というのがCLI版php.iniの場所です。




0 件のコメント:

コメントを投稿