0

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 May 04 '15 at 02:01
  • Possible duplicate of [date(): It is not safe to rely on the system's timezone settings in CodeIgniter](http://stackoverflow.com/questions/16765158/date-it-is-not-safe-to-rely-on-the-systems-timezone-settings-in-codeigniter) – jww May 04 '15 at 02:10
  • 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? –  May 04 '15 at 02:10
  • works 100% here on the 3 servers i have access to –  May 04 '15 at 02:10
  • i realized it was a problem with threading, thanks for your inputs though –  May 04 '15 at 02:20

1 Answers1

0

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
Scopey
  • 6,269
  • 1
  • 22
  • 34
  • shouldn't matter, date_default_timezone_set overrides the ini setting –  May 04 '15 at 02:13
  • i figured out the problem, timezone settings dont get passed to Thread_Async –  May 04 '15 at 02:15