#navi(../)
* PHPでstrtotimeでWarning (2): strtotime() ... が発生した時の対処方法 [#wf6eb493]
cakephp1.3.15をCentOS6にインストールして、初めてブラウザで接続したとき、以下のメッセージが表示されました。~
本資料は下記の警告の対処方法を記します。

#contents
#htmlinsertpcsp(web-top.html,web-sp.html)

 Warning (2): strtotime() [http://php.net/function.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 'Asia/Tokyo' for 'JST/9.0/no DST' instead [CORE/cake/libs/cache.php, line 597]
 Code | Context
 
 strtotime - [internal], line ??
 CacheEngine::init() - CORE/cake/libs/cache.php, line 597
 FileEngine::init() - CORE/cake/libs/cache/file.php, line 81
 Cache::_buildEngine() - CORE/cake/libs/cache.php, line 166
 Cache::config() - CORE/cake/libs/cache.php, line 141
 Configure::__loadBootstrap() - CORE/cake/libs/configure.php, line 429
 Configure::getInstance() - CORE/cake/libs/configure.php, line 52
 include - CORE/cake/bootstrap.php, line 38
 [main] - APP/webroot/index.php, line 79
 
 Notice: Trying to get property of non-object in /var/www/html/cakephp-cakephp-5e063d7/cake/libs/cache/file.php on line 262
 Fatal error: Call to a member function cd() on a non-object in /var/www/html/cakephp-cakephp-5e063d7/cake/libs/cache/file.php on line 262


* 使用した環境 [#q095619f]
- PHP~
PHP 5.3.3 (yumコマンドでPHPパッケージをインストールしました。)
- OS~
CentOS 6

* strtotimeのWarning対処方法 [#w71c8b29]
date_default_timezone_set関数でタイムゾーンを設定すればよいようですが、PHPスクリプトを触りたくないので、php.iniに以下の文字列を設定しました。
 date.timezone = Asia/Tokyo
タイムゾーン周りの参考資料は以下のリンクを参照してください。
-[[PHP実行時設定 Date/Time Configuration Options>http://jp.php.net/manual/ja/datetime.configuration.php]]

** php.iniの編集 [#lbf9ed23]
/etc/php.iniファイル内を確認すると、date.timezoneがコメントアウトされていました。
 ;;;;;;;;;;;;;;;;;;;
 ; Module Settings ;
 ;;;;;;;;;;;;;;;;;;;
 
 [Date]
 ; Defines the default timezone used by the date functions
 ; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
 ;date.timezone =
 <省略>

上記の ;date.timezone = を以下のように変更し保存しました。
 [Date]
 ; 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
 <省略>

** httpd(Apache)の再起動 [#d9e73bee]
php.iniの編集が完了したらhttpd(Apache)を再起動します。~
今回使用したOSはCentOSなので、rootユーザーにて以下のコマンドでhttpd(Apache)を再起動しました。
 [root@centos6 ~]# service httpd restart
 httpd を停止中:                                            [  OK  ]
 httpd を起動中:                                            [  OK  ]

以上の操作により、strtotime関数がWARNINGにならず動作するようになります。

#htmlinsertpcsp(web-btm.html,web-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS