php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74232 strtotime different output from centos and ubuntu
Submitted: 2017-03-10 05:51 UTC Modified: 2017-03-26 02:08 UTC
From: 729021170 at qq dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.30 OS: centos
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 729021170 at qq dot com
New email:
PHP Version: OS:

 

 [2017-03-10 05:51 UTC] 729021170 at qq dot com
Description:
------------
the above is centos, the below is ubuntu, strtotime('1927-12-31 23:54:02') is different (-1325491915, -1325491558)

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             4
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 63
Stepping:              2
CPU MHz:               2400.058
BogoMIPS:              4800.11
Hypervisor vendor:     Xen
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              15360K
NUMA node0 CPU(s):     0-3

1927-12-31 23:54:00 -1325491917			
1927-12-31 23:54:01 -1325491916			
1927-12-31 23:54:02 -1325491915			
1927-12-31 23:54:03 -1325491557			
1927-12-31 23:54:04 -1325491556			
1927-12-31 23:54:05 -1325491555			
1927-12-31 23:54:06 -1325491554			
1927-12-31 23:54:07 -1325491553			
1927-12-31 23:54:08 -1325491552			
1927-12-31 23:54:09 -1325491551			


Architecture:          	x86_64
CPU 运行模式:    		32-bit, 64-bit
Byte Order:            	Little Endian
CPU(s):                	4
On-line CPU(s) list:   	0-3
每个核的线程数:			2
每个座的核数:  			2
Socket(s):             	1
NUMA 节点:         		1
厂商 ID:           		GenuineIntel
CPU 系列:          		6
型号:              		78
Model name:            	Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
步进:              		3
CPU MHz:             	429.562
CPU max MHz:           	2800.0000
CPU min MHz:           	400.0000
BogoMIPS:              	4800.44
虚拟化:           		VT-x
L1d 缓存:          		32K
L1i 缓存:          		32K
L2 缓存:           		256K
L3 缓存:           		3072K
NUMA node0 CPU(s):     	0-3

1927-12-31 23:54:00 -1325491560
1927-12-31 23:54:01 -1325491559
1927-12-31 23:54:02 -1325491558
1927-12-31 23:54:03 -1325491557
1927-12-31 23:54:04 -1325491556
1927-12-31 23:54:05 -1325491555
1927-12-31 23:54:06 -1325491554
1927-12-31 23:54:07 -1325491553
1927-12-31 23:54:08 -1325491552
1927-12-31 23:54:09 -1325491551


Test script:
---------------
<?php
$start = strtotime('1927-12-31 23:54:00');

for ($i = 0; $i < 10; $i++) {
    $tmp = strtotime("+$i seconds", $start);

    echo date("Y-m-d H:i:s", $tmp) . " " . $tmp . "\n";
}




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-10 17:33 UTC] cmb@php.net
-Package: Unknown/Other Function +Package: Date/time related
 [2017-03-11 21:07 UTC] rasmus@php.net
-Status: Open +Status: Feedback
 [2017-03-11 21:07 UTC] rasmus@php.net
Did you build both yourself?

Note that some distros link PHP against their own timezone db and if it differs from the one we bundle you will see results like this. If you build the same version of PHP yourself on both systems you should see the same result.
 [2017-03-11 22:07 UTC] heiglandreas@php.net
I can't see which timezone is set on the two servers. 358 seconds difference look like some issue with a timezone. 

Please check:
 * Timezone on the servers (date_default_timezone_get())
 * Which version of the timezonedb is installed (and linked to PHP) on the servers (php -i | grep Olson)
 [2017-03-12 02:29 UTC] 729021170 at qq dot com
The Server
PHP 5.5.9 (cli) (built: Dec  7 2015 15:37:14) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

date/time support => enabled
"Olson" Timezone Database Version => 2013.9
Timezone Database => internal
Default timezone => Asia/Shanghai
date.timezone => Asia/Shanghai => Asia/Shanghai

The Local
PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.15-0ubuntu0.16.04.4, Copyright (c) 1999-2017, by Zend Technologies

date/time support => enabled
"Olson" Timezone Database Version => 0.system
Timezone Database => internal
Default timezone => Asia/Shanghai
date.timezone => Asia/Shanghai => Asia/Shanghai

my doubt is why there is chasm between 1927-12-31 23:54:02(1325491915) and 1927-12-31 23:54:03(1325491557)
 [2017-03-12 09:39 UTC] heiglandreas@php.net
-Status: Feedback +Status: Not a bug
 [2017-03-12 09:39 UTC] heiglandreas@php.net
You stumbled over one of these strange offset issues in the TZ-Database: Have a look at https://github.com/eggert/tz/blob/68efd697628085f6461f66d8429431175f91c09a/asia#L395 - that adds an offset of 8 hours 5 minutes and 57 seconds to UTC on the 1st of january 1928 at exactly 00:00:00. So 1927-12-31 23:54:02 needs to be followed by 1928-1-1 00:00:00 which - due to it being a time before the epoch - will be calculated back to a timestamp that seems to be weird.

So it's not a bug in PHP as PHP is doing the calculations absolutely correct (hence I'm closing this). But it's an issue in the Timezone-Database that has been altered with https://github.com/eggert/tz/commit/15b01c042afa770acd5068054c50e7c5c663cbd2 in 2014. 

Due to your server using a rather outdated Timezone-Database and your dev-machine using the systems (up to date) version you get this mismatch. You should update your timezonedb on the server by either updating the PHP-Version or at least by updating the timezonedb using https://pecl.php.net/package/timezonedb
 [2017-03-26 02:08 UTC] 729021170 at qq dot com
I use the same timezonedb version, Set the same timezone Asia/Shanghai, Compile with the different php version, But it does't work, It seems only can to update php version to sovle the problem;


timezonedb https://pecl.php.net/get/timezonedb-2017.2.tgz

php5.5 http://php.net/get/php-5.5.38.tar.gz/from/a/mirror
php5.6 http://php.net/get/php-5.6.30.tar.gz/from/a/mirror
php7.0 http://php.net/get/php-7.0.17.tar.gz/from/a/mirror

➜  bin /data/service/php5.5/bin/php /data/www/test/test.php
-2209017943
2017-03-26 09:49:39
2017.2
➜  bin /data/service/php5.6/bin/php /data/www/test/test.php
-2209017600
2017-03-26 09:49:45
2017.2
➜  bin /data/service/php7.0/bin/php /data/www/test/test.php
-2209017600
2017-03-26 09:49:52
2017.2
➜  bin
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 01:01:31 2024 UTC