php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38154 PHP CLI filemtime() is wrong
Submitted: 2006-07-19 23:26 UTC Modified: 2006-10-26 01:00 UTC
Votes:6
Avg. Score:3.8 ± 0.9
Reproduced:6 of 6 (100.0%)
Same Version:1 (16.7%)
Same OS:2 (33.3%)
From: dave at smartboy dot com Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 5.1.4 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dave at smartboy dot com
New email:
PHP Version: OS:

 

 [2006-07-19 23:26 UTC] dave at smartboy dot com
Description:
------------
Using PHP CLI on Windows - filemtime() returns an incorrect value.

This problem does NOT occur with the Apache 2 SAPI.

Value reported is ahead by 9 hours (could be time zone related?  I am in GMT+10:00 time zone)

Sample output:

$ php test_filemtime.php
2006-07-20 18:20:08

$ ls -l test_filemtime.php
-rw-r--r-- 1 Dave None 81 Jul 20 09:20 test_filemtime.php

(the above from Cygwin)

When running the exact same script inside Apache2 the correct time is printed

2006-07-20 09:20:08


Reproduce code:
---------------
<?php

echo date('Y-m-d H:i:s', filemtime($_SERVER["SCRIPT_FILENAME"])) . "\n";

Expected result:
----------------
2006-07-20 09:20:08

Actual result:
--------------
2006-07-20 18:20:08

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-20 15:20 UTC] mike@php.net
Set date.timezone to your timezone.
 [2006-07-22 01:41 UTC] dave at smartboy dot com
Setting date.timezone does not change the behaviour.  Changing the sample script to:

<?php

echo "default timezone: " . date_default_timezone_get() . "\n";

date_default_timezone_set("Australia/Brisbane");

echo "default timezone: " . date_default_timezone_get() . "\n";

echo date('Y-m-d H:i:s', filemtime($_SERVER["SCRIPT_FILENAME"])) . "\n";


produces this output:

$ php test_filemtime.php
default timezone: Australia/Melbourne
default timezone: Australia/Brisbane
2006-07-22 20:35:22

Which is still 9 hours greater than it should be.

When using Apache2 SAPI, the following (correct) output is generated:

default timezone: Australia/Melbourne
default timezone: Australia/Brisbane
2006-07-22 11:35:22


Changing "Australia/Brisbane" to "UTC" changes the time that is printed, however there is still a 9 hour difference between the value printed by CLI (2006-07-22 10:39:47) and the value printed by Apache2 SAPI (2006-07-22 01:39:47)
 [2006-07-22 08:33 UTC] derick@php.net
Can you get rid of the date() calls so that we can rule out that that is the problem and not filemtime?
 [2006-07-23 04:07 UTC] dave at smartboy dot com
Changed test_filemtime.php to:

<?php

echo filemtime($_SERVER["SCRIPT_FILENAME"]) . "\n";
date_default_timezone_set("UTC");
echo filemtime($_SERVER["SCRIPT_FILENAME"]) . "\n";


Output is:

$ php test_filemtime.php
1153659348
1153659348


So, the return from filemtime() is not affected by the date.timezone setting.  However the value is out by 9 hours.  This is the expected return value: 

$ stat -c%Z test_filemtime.php
1153626948

(this matches very closely the output of date +%s, as I had just saved the file when running the above command)

And the difference is 9 hours

$ echo $((1153659348-1153626948))
32400

$ echo $((9*3600))
32400
 [2006-09-18 06:48 UTC] derick@php.net
Unassigning as this has nothing to do with the date code.
 [2006-10-18 21:16 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

Not reproducible.
 [2006-10-26 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-08-18 01:46 UTC] dheathorn at gmail dot com
I'm having the same issue of filemtime() reporting 9 hours ahead of when it is suppose to
I'm on Windows XP running PHP v5.2.0
I tested this on Linux running PHP v5.1.6 and it reported correctly.
In my opinion it's a bug relating to PHP under Windows XP.
 [2007-08-18 01:58 UTC] dheathorn at gmail dot com
Nevermind about my last comment. This bug has been fixed in latest version of PHP. I should have tried this first.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 10:01:33 2025 UTC