2012-08-24 52 views
8

我在php.ini文件此項:PHP date.timezone不是命令行腳本正常工作,只有

date.timezone = 'Europe/London'; 

但我每次在命令行腳本中使用的DateTime()時我仍然得到以下錯誤:

Exception: DateTime::__construct(): 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 'Europe/London' for 'BST/1.0/DST' instead 

因此,我必須做的任何腳本下面來得到這個工作:

date_default_timezone_set('Europe/London'); 

w ^否則可能會導致此錯誤?

UPDATE

我曾經在這兩個命令行和Web瀏覽器中執行以下操作:

<?php 

var_dump(ini_get('date.timezone')); 
exit; 

在命令行中,我得到:

string(0) "" 

在Web瀏覽器中,我得到:

string(13) "Europe/London" 
+2

你改變php.ini文件後,重新啓動服務器的問題? –

+0

是的,它已被重新啓動,但該值已被設置了一段時間,並且服務器之間已經多次重新啓動。它只是現在,當我寫一個命令行腳本,發生異常 – user1572427

+0

你可以嘗試echo ini_get('date.timezone');看看實際設置了什麼? –

回答

17

CLI和網絡服務器(以及cgi和fpm)使用不同的php.ini文件。因爲你說你在瀏覽器中看到了正確的價值,我想你編輯了錯誤的一個。在氣候類型

php --ini 

要了解哪些是您必須編輯的。這是一個在第二行,例如

Loaded Configuration File:   /etc/php5/cli/php.ini 
1

有些服務器(如媒體寺)做配置爲特定domains.So服務器將訪問通用php.ini文件是根據在/ etc/php.ini中,但瀏覽器訪問該域名的php.ini中file.It可能發生

+1

這是關於CLI,什麼是域獨立。 – KingCrunch

相關問題