PHP配置datetime.zone時注意點____PHP

來源:互聯網
上載者:User

1、閑來搞下PHP的東東,今天搭了下PHP的運行環境,在測試date函數時老報如下錯:

"PHP Warning: date() [function.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. We selected 'UTC' for '8.0/no DST' instead in"XXX

上網查了下資料,解決方案有三: 一、在頁頭使用date_default_timezone_set()設定 date_default_timezone_set('PRC'); //東八時區 echo date('Y-m-d H:i:s'); 二、在頁頭使用 ini_set('date.timezone','Asia/Shanghai'); 三、修改php.ini。開啟php5.ini尋找date.timezone 去掉前面的分號修改成為:date.timezone =PRC或Asia/Shanghai

 

看了下php.ini裡面有個datetime.zone的選項:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =

訪問http://php.net/date.timezone 可以看到相關的內容,裡面提到china配置的時區:

// Shanghai, China, Asia
date.timezone = "Asia/Shanghai"
date.default_latitude = 31.5167
date.default_longitude = 121.4500

改完配置後,重啟apache,運行看了下,還是報一樣的錯,就是說改的東西沒有生效,但試了下其它的兩種方法是可以的。

後面在apache設定檔httpd.conf配置支援php的地方加上:PHPIniDir "D:/php5.4.7" 問題解決

Apache 設定的時候 PHPIniDir 有什麼作用呢。
與php4搜尋php.ini是在%SystemRoot%下不同的是,PHP5按照以下順序依次尋找PHP.ini:

* PHPIniDir (Apache 2 module only)
* 註冊表索引值:HKEY_LOCAL_MACHINE—SOFTWARE—PHPIniFilePath
* 環境變數:%PHPRC%
* PHP5的目錄 (for CLI), 或者web伺服器目錄(for SAPI modules)
* Windows目錄(C:\windows or C:\winnt)
所以如果是Apache + PHP5的話可以使用 PHPIniDir 指定php5的設定檔php.ini的路徑。

#以apache的模組方式運行php,全部配置如下:

LoadModule php5_module modules/php5apache2_2.dll
PHPIniDir "D:/php5.4.7"
AddType application/x-httpd-php .php .html

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.