Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTC Default timezone instead of server local timezone ? #11496

Closed
Wait4Code opened this issue Jun 21, 2023 · 7 comments
Closed

UTC Default timezone instead of server local timezone ? #11496

Wait4Code opened this issue Jun 21, 2023 · 7 comments

Comments

@Wait4Code
Copy link

Description

After upgrading my php version from 8.1 to 8.2 I've noticed that the default timezone changed from the server local to UTC.
To be sure that it does not come from my server setup or my computer, i've set up 2 differents Dockerfile based on Ubuntu 22.04 and based on the same local timezone : one with php 8.1 and another with php 8.2.

The one with PHP 8.1 correctly use the container TZ while the other one use UTC.

I've also noticed the same behaviour with Ubuntu 18.04 and 20.04.

Is that a new behaviour of PHP8.2 ? Am I missing something ?

Be aware that php.ini config files are left untouched, they are by default.

Here are the Dockerfiles

PHP 8.1 :

FROM ubuntu:22.04

RUN apt-get update --fix-missing
RUN apt-get install -y software-properties-common

RUN apt-get update && \
    apt-get install -yq tzdata && \
    ln -fs /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata

RUN add-apt-repository -y ppa:ondrej/php
RUN apt update
RUN apt install -y php8.1


CMD date; php -r 'print_r(new \DateTime("now"));'

Output :

Wed Jun 21 08:00:22 CEST 2023
DateTime Object
(
    [date] => 2023-06-21 08:00:22.532719
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)

PHP 8.2 :

FROM ubuntu:22.04

RUN apt-get update --fix-missing
RUN apt-get install -y software-properties-common

RUN apt-get update && \
    apt-get install -yq tzdata && \
    ln -fs /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata

RUN add-apt-repository -y ppa:ondrej/php
RUN apt update
RUN apt install -y php8.2


CMD date; php -r 'print_r(new \DateTime("now"));'

Output :

Wed Jun 21 08:00:16 CEST 2023
DateTime Object
(
    [date] => 2023-06-21 06:00:16.449674
    [timezone_type] => 3
    [timezone] => UTC
)

PHP Version

PHP 8.2

Operating System

Ubuntu 22.04

@nielsdos
Copy link
Member

Hmm 🤔 something did indeed change in 8.2: 6770158 to make UTC the default if unspecified. I didn't find this in the documentation though.
In general you should set the date.timezone field in the php.ini to configure your default timezone. That behaviour will always be reproducible.

@Wait4Code
Copy link
Author

Hmm 🤔 something did indeed change in 8.2: 6770158 to make UTC the default if unspecified. I didn't find this in the documentation though. In general you should set the date.timezone field in the php.ini to configure your default timezone. That behaviour will always be reproducible.

Well, thanks you for your answer, at least It enlightens me on this behavior. I know (and I should have use it) that with the date.timezone configuration attribute, I can stably set the timezone.

But is this not a kind of breaking change ? If this is a bad practice to let this configuration untouched and let the server "decide" which TZ will be used in PHP, wouldn't it be better to make that deprecated in this minor version and definitely set the default value in next major version ?

@nielsdos
Copy link
Member

I don't know the full context of this. So I'll cc the author of the commit. cc @derickr

@derickr
Copy link
Contributor

derickr commented Nov 22, 2023

I believe PHP would always have used UTC, even if it was empty.

Some distributions change how PHP works in regard to timezones, and come up with a "timezone-local" moniker that isn't standard. That is however, a problem with how distributions patch PHP. For pure PHP, this should not have bea BC breaking change.

@derickr derickr closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2023
@mbniehues
Copy link

mbniehues commented Dec 29, 2023

This one tripped me up too using ubuntu 20.04 and upgrading PHP 7.4 to 8.2. I confirmed that on PHP 7.4, PHP uses the operating system's timezone. But, after upgrading to 8.2, it's using UTC and dates in logging and database were now shifted. While perhaps not an issue with core PHP, it sure would be nice for the upgrade notes to contain something about this because upgrading on a common OS (Ubuntu) seems to cause this.

@nicodemuz
Copy link

I too encountered a few application errors after upgrading from PHP version 8.1 to 8.3 due to timezone changing from server timezone to UTC.

I agree with @mbniehues that the upgrade notes and change log should mention about this.

@suwalski
Copy link

Any chance this is going to get fixed? It is POSIX standard to inherit and execute in the timezone specified.

#> TZ=Asia/Tokyo php foo.php should execute in Tokyo time, and it's rather broken that it comes back in UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants