0
votes

At the beginning of my configuration file I have:

    date_default_timezone_set('America/Los_Angeles');
    echo "Set default timezone: " . date_default_timezone_get() . "\n";
   ...

I execute PHP script via CLI and the output looks like this:

Set default timezone: America/Los_Angeles

PHP Warning: 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in

Why am I receiving the message "It is not safe to rely on the system's timezone settings" even after setting the timezone?

------ UPDATE ---------

Turns out this is a threading problem, so need to set to php.ini to solve it.

<?php

require __DIR__ . '/config.php';

date_default_timezone_set('America/Los_Angeles');

echo "Timezone: " . date_default_timezone_get() . "\n";

function threadTest() {
    echo "Thread Timezone: " . date_default_timezone_get() . "\n";
}

$thread = new Thread_Async();
$thread->call('threadTest');

Results:

Timezone: America/Los_Angeles

PHP Warning: date_default_timezone_get(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /pvolf/wwwdev/app/test.php on line 10

Thread Timezone: UTC

1
I tested your code on CLI and browser and I cannot reproduce the error. Are you sure you've saved the file already ?Pedro Lobito
i think this is happening inside a Thread_Async object, could that be the cause? Perhaps timezone settings dont get copied over when you make a new thread?user2914191
works 100% here on the 3 servers i have access touser557846
i realized it was a problem with threading, thanks for your inputs thoughuser2914191

1 Answers

0
votes

Check your ini that's used for command line. I bet it has no timezone set. Try running command line with -d date.timezone=UTC eg:

php -d date.timezone=UTC foo.php