php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29051 Unix timestamp mismatch
Submitted: 2004-07-07 16:18 UTC Modified: 2004-07-11 20:13 UTC
From: daseymour at 3hc dot org Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.3.7 OS: Windows 2000 (5.00.2195 - SP4)
Private report: No CVE-ID: None
 [2004-07-07 16:18 UTC] daseymour at 3hc dot org
Description:
------------
The following date/time functions give different results when requesting the current unix timestamp...

Microtime()
GetTimeOfDay()
Time()
Date()
GetDate()

This problem occurs on Apache 2.0.47 and Apache 1.3.31, but it doesn't seem to occur on IIS 5.0.

Reproduce code:
---------------
<?PHP
	
	list($tmp, $sec1) = explode(" ", microtime());
	$tmp = gettimeofday();
	$sec2 = $tmp['sec'];
	$sec3 = time();	
	$sec4 = date('U');
	$tmp = getdate();
	$sec5 = $tmp[0];
	echo "These should all be the same<br /><br />";
	echo "<table>";
	echo "<tr><td><b>Microtime()</b>:</td><td>$sec1</td></tr>";
	echo "<tr><td><b>GetTimeOfDay()</b>:</td><td>$sec2</td></tr>";
	echo "<tr><td><b>Time()</b>:</td><td>$sec3</td></tr>";	
	echo "<tr><td><b>Date()</b>:</td><td>$sec4</td></tr>";
	echo "<tr><td><b>GetDate()</b>:</td><td>$sec5</td></tr>";
	echo "</table><br /><br /><hr />";	
	echo "<i>PHP Version: " . phpversion() . "&nbsp; &nbsp; Server API: " . php_sapi_name() . "</i>";
	
?>

Expected result:
----------------
The unix timestamps returned by the above functions should all  be the same.

Actual result:
--------------
It appears that Microtime() and GetTimeOfDay() are returning different results than Time(), Date(), and GetDate().

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-07 16:30 UTC] derick@php.net
Works fine for me...
 [2004-07-07 16:38 UTC] daseymour at 3hc dot org
Derick, what OS and PHP version are you running?  This problem only seems to occur on my Win2k box with Apache.

Thanks.
 [2004-07-08 11:30 UTC] sniper@php.net
Please give an example output of the wrong results you got.

 [2004-07-08 16:13 UTC] daseymour at 3hc dot org
Output #1 (Win2k, Apache 1.3.31, PHP 4.3.7):
----------------------------------------------
These should all be the same

Microtime():	1089290860
GetTimeOfDay():	1089290860
Time():		1089290856
Date():		1089290856
GetDate():	1089290856


PHP Version: 4.3.7    Server API: apache



Output #2 (Win2k, Apache 1.3.31, PHP 4.3.7):
----------------------------------------------
These should all be the same

Microtime():	1089291058
GetTimeOfDay():	1089291058
Time():		1089291053
Date():		1089291053
GetDate():	1089291053


PHP Version: 4.3.7    Server API: apache



Output #3 (Win2k, Apache 2.0.47, PHP 4.3.7 - Most of the time on this setup, it will work correctly...):
----------------------------------------------
These should all be the same

Microtime():	1089295702
GetTimeOfDay():	1089295702
Time():		1089295702
Date():		1089295702
GetDate():	1089295702


PHP Version: 4.3.7    Server API: apache2handler



Output #4 (Win2k, Apache 2.0.47, PHP 4.3.7 - But, every so often, it is incorrect...):
----------------------------------------------
These should all be the same

Microtime():	1089295596 
GetTimeOfDay():	1089295596 
Time():		1089295595 
Date():		1089295595 
GetDate():	1089295595 


--------------------------------------------------------------------------------
PHP Version: 4.3.7    Server API: apache2handler
 [2004-07-11 20:13 UTC] sniper@php.net
I did some research (using google :) and found several notes about problems with gettimeofday() implementations under Windows. "Windows is not a real-time operating system." :)

Read more here: http://www.flounder.com/time.htm

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 13:01:34 2024 UTC