I have this entry in my php.ini file:
date.timezone = 'Europe/London';
But every time i use the DateTime() in a command line script i still get the following error:
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
I therefore have to do the following in any scripts to get this to work:
date_default_timezone_set('Europe/London');
What else can be causing this error?
UPDATE
I used the following in both command line and web browser:
<?php
var_dump(ini_get('date.timezone'));
exit;
In command line i get:
string(0) ""
In web browser i get:
string(13) "Europe/London"
Reading the timezone set using the date_default_timezone_set() function (if any) Reading the value of the date. timezone ini option (if set) If none of the above succeed, the default timezone will be UTC.
The date_default_timezone_get() function returns the default timezone used by all date/time functions in the script.
CLI and webserver (and cgi and fpm) use different php.ini
-files. Because you say you see the right value in you browser I guess you edited the wrong one. On cli type
php --ini
To find out, which is the one you must edit. It's the one in the second line, for example
Loaded Configuration File: /etc/php5/cli/php.ini
Some servers(Like media temple) do the configurations for the particular domains.So the server will access the common php.ini file which is under the /etc/php.ini but the browser access the domain's php.ini file.It may occurs the problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With