php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42226 microtime is not save under windows
Submitted: 2007-08-06 22:04 UTC Modified: 2007-08-11 11:56 UTC
From: bjoern at xrow dot de Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.4RC1 & 4.4.7 OS: Windows
Private report: No CVE-ID: None
 [2007-08-06 22:04 UTC] bjoern at xrow dot de
Description:
------------
This bug occurs under php4 and php5.

It might occur that the micro time might output a date older then the date it had output before.

php5 does worse then php4.

Reproduce code:
---------------
<?php
$last = null;
for ($i=1;$i<=100000;$i++)
{
   list($micro,$time)=explode(" ",microtime());
   $add=$micro+$time;
   if ( $last !== null )
   print ($add<$last ? 'Run '.$i.' Last:'.$last.' -Current:'.$add."\r\n" : '');
   $last=$add; 
}
?>

Expected result:
----------------
C:\workspace>php microtimebug.php
(nothing)
C:\workspace>C:\php5\php.exe microtimebug.php
(nothing)

Actual result:
--------------
C:\workspace>php microtimebug.php
Run 2690 Last:1186437375.2899 -Current:1186437374.2495
Run 23377 Last:1186437375.4714 -Current:1186437374.437
Run 30341 Last:1186437375.534 -Current:1186437374.4995
Run 36083 Last:1186437375.5787 -Current:1186437374.5464
Run 49990 Last:1186437375.6881 -Current:1186437374.6557
Run 62669 Last:1186437375.7984 -Current:1186437374.7651
Run 68143 Last:1186437375.8433 -Current:1186437374.7964
Run 75918 Last:1186437375.8971 -Current:1186437374.8745
Run 82398 Last:1186437375.9586 -Current:1186437374.9214
Run 90123 Last:1186437376.0163 -Current:1186437374.9839
Run 99605 Last:1186437376.0827 -Current:1186437375.062

C:\workspace>C:\php5\php.exe microtimebug.php
Run 11 Last:1186436769.93 -Current:1186436768.89
Run 260 Last:1186436769.96 -Current:1186436768.92
Run 998 Last:1186436770.04 -Current:1186436769
Run 1392 Last:1186436770.08 -Current:1186436769.05
Run 2180 Last:1186436770.17 -Current:1186436769.14
Run 3123 Last:1186436770.27 -Current:1186436769.25
Run 3657 Last:1186436770.34 -Current:1186436769.31
Run 4137 Last:1186436770.4 -Current:1186436769.36
Run 4514 Last:1186436770.44 -Current:1186436769.41
Run 4900 Last:1186436770.47 -Current:1186436769.45
Run 5317 Last:1186436770.53 -Current:1186436769.5
Run 5639 Last:1186436770.56 -Current:1186436769.53
Run 6138 Last:1186436770.62 -Current:1186436769.59
Run 6299 Last:1186436770.63 -Current:1186436769.61
Run 7112 Last:1186436770.73 -Current:1186436769.7
Run 7402 Last:1186436770.77 -Current:1186436769.73
Run 8066 Last:1186436770.85 -Current:1186436769.81
Run 8496 Last:1186436770.9 -Current:1186436769.86
Run 8904 Last:1186436770.94 -Current:1186436769.91
Run 9161 Last:1186436770.97 -Current:1186436769.94
Run 9971 Last:1186436771.07 -Current:1186436770.03
Run 10375 Last:1186436771.12 -Current:1186436770.08
Run 10738 Last:1186436771.16 -Current:1186436770.12
Run 10950 Last:1186436771.18 -Current:1186436770.14
Run 11612 Last:1186436771.26 -Current:1186436770.22
Run 11819 Last:1186436771.27 -Current:1186436770.25
Run 12361 Last:1186436771.33 -Current:1186436770.31
Run 12690 Last:1186436771.38 -Current:1186436770.34
Run 13394 Last:1186436771.46 -Current:1186436770.42
Run 13677 Last:1186436771.49 -Current:1186436770.45
Run 13728 Last:1186436771.5 -Current:1186436770.47
Run 14085 Last:1186436771.53 -Current:1186436770.5
Run 14553 Last:1186436771.58 -Current:1186436770.56
Run 14636 Last:1186436771.6 -Current:1186436770.56
Run 14978 Last:1186436771.65 -Current:1186436770.61
Run 15380 Last:1186436771.69 -Current:1186436770.66
Run 15750 Last:1186436771.73 -Current:1186436770.7
Run 16024 Last:1186436771.77 -Current:1186436770.73
Run 16719 Last:1186436771.84 -Current:1186436770.81
Run 17586 Last:1186436771.94 -Current:1186436770.91
Run 18366 Last:1186436772.03 -Current:1186436771
Run 18911 Last:1186436772.09 -Current:1186436771.06
Run 19178 Last:1186436772.13 -Current:1186436771.09
Run 19516 Last:1186436772.16 -Current:1186436771.12
Run 19743 Last:1186436772.19 -Current:1186436771.16
Run 20118 Last:1186436772.23 -Current:1186436771.19
Run 20527 Last:1186436772.27 -Current:1186436771.23
Run 21095 Last:1186436772.34 -Current:1186436771.31
Run 21526 Last:1186436772.39 -Current:1186436771.36
Run 22115 Last:1186436772.46 -Current:1186436771.42
Run 22320 Last:1186436772.49 -Current:1186436771.45
Run 23076 Last:1186436772.56 -Current:1186436771.53
Run 23278 Last:1186436772.6 -Current:1186436771.56
Run 23943 Last:1186436772.67 -Current:1186436771.64
Run 24733 Last:1186436772.75 -Current:1186436771.73
Run 25046 Last:1186436772.79 -Current:1186436771.77
Run 25635 Last:1186436772.87 -Current:1186436771.83
Run 25839 Last:1186436772.88 -Current:1186436771.86
Run 26264 Last:1186436772.94 -Current:1186436771.91
Run 27403 Last:1186436773.07 -Current:1186436772.03
Run 27747 Last:1186436773.1 -Current:1186436772.08
Run 28045 Last:1186436773.14 -Current:1186436772.11
Run 29280 Last:1186436773.28 -Current:1186436772.25
Run 29825 Last:1186436773.34 -Current:1186436772.31
Run 30124 Last:1186436773.37 -Current:1186436772.34
Run 30852 Last:1186436773.45 -Current:1186436772.42
Run 31480 Last:1186436773.52 -Current:1186436772.5
Run 32045 Last:1186436773.6 -Current:1186436772.56
Run 32482 Last:1186436773.65 -Current:1186436772.61
Run 32916 Last:1186436773.68 -Current:1186436772.66
Run 33287 Last:1186436773.73 -Current:1186436772.7
Run 33664 Last:1186436773.78 -Current:1186436772.73
Run 34277 Last:1186436773.85 -Current:1186436772.81
Run 34711 Last:1186436773.9 -Current:1186436772.86
Run 34844 Last:1186436773.91 -Current:1186436772.87
Run 35312 Last:1186436773.96 -Current:1186436772.92
Run 35482 Last:1186436773.99 -Current:1186436772.95
Run 35873 Last:1186436774.02 -Current:1186436772.98
Run 36660 Last:1186436774.12 -Current:1186436773.08
Run 36879 Last:1186436774.15 -Current:1186436773.11
Run 37499 Last:1186436774.21 -Current:1186436773.17
Run 37689 Last:1186436774.24 -Current:1186436773.2
Run 38098 Last:1186436774.28 -Current:1186436773.25
Run 38388 Last:1186436774.32 -Current:1186436773.28
Run 38840 Last:1186436774.37 -Current:1186436773.33
Run 39734 Last:1186436774.48 -Current:1186436773.44
Run 40787 Last:1186436774.59 -Current:1186436773.56
Run 41211 Last:1186436774.65 -Current:1186436773.61
Run 41634 Last:1186436774.7 -Current:1186436773.66
Run 42008 Last:1186436774.74 -Current:1186436773.7
Run 42304 Last:1186436774.77 -Current:1186436773.73
Run 42741 Last:1186436774.83 -Current:1186436773.78
Run 42915 Last:1186436774.83 -Current:1186436773.81
Run 43221 Last:1186436774.88 -Current:1186436773.84
Run 43743 Last:1186436774.94 -Current:1186436773.91
Run 44022 Last:1186436774.98 -Current:1186436773.94
Run 44678 Last:1186436775.05 -Current:1186436774.02
Run 45296 Last:1186436775.12 -Current:1186436774.08
Run 45597 Last:1186436775.15 -Current:1186436774.11
Run 45915 Last:1186436775.19 -Current:1186436774.16
Run 47068 Last:1186436775.32 -Current:1186436774.28
Run 47589 Last:1186436775.39 -Current:1186436774.34
Run 47780 Last:1186436775.41 -Current:1186436774.37
Run 48483 Last:1186436775.48 -Current:1186436774.45
Run 48835 Last:1186436775.53 -Current:1186436774.48
Run 49214 Last:1186436775.57 -Current:1186436774.53
Run 50172 Last:1186436775.68 -Current:1186436774.64
Run 50958 Last:1186436775.76 -Current:1186436774.73
Run 51880 Last:1186436775.87 -Current:1186436774.84
Run 52736 Last:1186436775.97 -Current:1186436774.94
Run 53281 Last:1186436776.02 -Current:1186436775
Run 53748 Last:1186436776.08 -Current:1186436775.05
Run 54278 Last:1186436776.15 -Current:1186436775.11
Run 54627 Last:1186436776.18 -Current:1186436775.16
Run 55421 Last:1186436776.28 -Current:1186436775.25
Run 55871 Last:1186436776.34 -Current:1186436775.3
Run 56932 Last:1186436776.45 -Current:1186436775.42
Run 57627 Last:1186436776.52 -Current:1186436775.5
Run 58138 Last:1186436776.59 -Current:1186436775.56
Run 58565 Last:1186436776.64 -Current:1186436775.61
Run 58991 Last:1186436776.69 -Current:1186436775.66
Run 59685 Last:1186436776.77 -Current:1186436775.73
Run 60260 Last:1186436776.83 -Current:1186436775.8
Run 60713 Last:1186436776.88 -Current:1186436775.84
Run 61153 Last:1186436776.93 -Current:1186436775.89
Run 61330 Last:1186436776.96 -Current:1186436775.92
Run 61755 Last:1186436777.01 -Current:1186436775.97
Run 62549 Last:1186436777.09 -Current:1186436776.06
Run 62926 Last:1186436777.14 -Current:1186436776.09
Run 63094 Last:1186436777.16 -Current:1186436776.12
Run 63388 Last:1186436777.18 -Current:1186436776.16
Run 63787 Last:1186436777.23 -Current:1186436776.2
Run 64203 Last:1186436777.27 -Current:1186436776.25
Run 64521 Last:1186436777.32 -Current:1186436776.28
Run 65836 Last:1186436777.47 -Current:1186436776.44
Run 66443 Last:1186436777.54 -Current:1186436776.5
Run 66925 Last:1186436777.6 -Current:1186436776.56
Run 67280 Last:1186436777.63 -Current:1186436776.59
Run 67606 Last:1186436777.67 -Current:1186436776.64
Run 68164 Last:1186436777.74 -Current:1186436776.7
Run 68359 Last:1186436777.76 -Current:1186436776.72
Run 68363 Last:1186436777.75 -Current:1186436776.72
Run 68435 Last:1186436777.76 -Current:1186436776.73
Run 68976 Last:1186436777.83 -Current:1186436776.8
Run 69481 Last:1186436777.87 -Current:1186436776.84
Run 69950 Last:1186436777.94 -Current:1186436776.91
Run 70247 Last:1186436777.97 -Current:1186436776.94
Run 70769 Last:1186436778.03 -Current:1186436777
Run 71179 Last:1186436778.08 -Current:1186436777.05
Run 71480 Last:1186436778.12 -Current:1186436777.08
Run 71753 Last:1186436778.15 -Current:1186436777.11
Run 71891 Last:1186436778.16 -Current:1186436777.12
Run 72556 Last:1186436778.23 -Current:1186436777.2
Run 72962 Last:1186436778.28 -Current:1186436777.25
Run 73856 Last:1186436778.39 -Current:1186436777.34
Run 73914 Last:1186436778.38 -Current:1186436777.36
Run 74338 Last:1186436778.43 -Current:1186436777.41
Run 74723 Last:1186436778.48 -Current:1186436777.45
Run 75145 Last:1186436778.53 -Current:1186436777.5
Run 76124 Last:1186436778.64 -Current:1186436777.61
Run 76534 Last:1186436778.69 -Current:1186436777.66
Run 77165 Last:1186436778.77 -Current:1186436777.73
Run 77816 Last:1186436778.84 -Current:1186436777.81
Run 78365 Last:1186436778.91 -Current:1186436777.87
Run 78649 Last:1186436778.94 -Current:1186436777.91
Run 79462 Last:1186436779.04 -Current:1186436778
Run 79690 Last:1186436779.05 -Current:1186436778.03
Run 79975 Last:1186436779.1 -Current:1186436778.06
Run 80437 Last:1186436779.15 -Current:1186436778.11
Run 81083 Last:1186436779.23 -Current:1186436778.19
Run 81459 Last:1186436779.25 -Current:1186436778.23
Run 82171 Last:1186436779.35 -Current:1186436778.31
Run 82481 Last:1186436779.39 -Current:1186436778.34
Run 83058 Last:1186436779.45 -Current:1186436778.42
Run 83193 Last:1186436779.47 -Current:1186436778.44
Run 84270 Last:1186436779.59 -Current:1186436778.56
Run 84892 Last:1186436779.66 -Current:1186436778.62
Run 85105 Last:1186436779.68 -Current:1186436778.66
Run 85771 Last:1186436779.77 -Current:1186436778.73
Run 86203 Last:1186436779.82 -Current:1186436778.78
Run 86799 Last:1186436779.88 -Current:1186436778.84
Run 87276 Last:1186436779.93 -Current:1186436778.91
Run 87559 Last:1186436779.97 -Current:1186436778.94
Run 88066 Last:1186436780.03 -Current:1186436779
Run 88519 Last:1186436780.07 -Current:1186436779.05
Run 89020 Last:1186436780.14 -Current:1186436779.11
Run 89293 Last:1186436780.17 -Current:1186436779.14
Run 89826 Last:1186436780.24 -Current:1186436779.2
Run 90241 Last:1186436780.28 -Current:1186436779.25
Run 90650 Last:1186436780.33 -Current:1186436779.3
Run 91171 Last:1186436780.38 -Current:1186436779.34
Run 91940 Last:1186436780.47 -Current:1186436779.44
Run 92359 Last:1186436780.52 -Current:1186436779.48
Run 93010 Last:1186436780.6 -Current:1186436779.56
Run 93572 Last:1186436780.66 -Current:1186436779.62
Run 93864 Last:1186436780.69 -Current:1186436779.66
Run 94398 Last:1186436780.75 -Current:1186436779.72
Run 94543 Last:1186436780.77 -Current:1186436779.73
Run 94891 Last:1186436780.81 -Current:1186436779.77
Run 95208 Last:1186436780.85 -Current:1186436779.81
Run 95839 Last:1186436780.92 -Current:1186436779.89
Run 96418 Last:1186436780.98 -Current:1186436779.95
Run 96830 Last:1186436781.03 -Current:1186436780
Run 97471 Last:1186436781.1 -Current:1186436780.06
Run 97769 Last:1186436781.14 -Current:1186436780.11
Run 97857 Last:1186436781.15 -Current:1186436780.11
Run 98192 Last:1186436781.18 -Current:1186436780.16
Run 98572 Last:1186436781.24 -Current:1186436780.2
Run 98982 Last:1186436781.28 -Current:1186436780.25
Run 99900 Last:1186436781.39 -Current:1186436780.34

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-07 12:51 UTC] iliaa@php.net
Have you tried calling microtime(1) <-- this returns you a floating 
point number directly.
 [2007-08-07 13:04 UTC] bjoern at xrow dot de
Here is the script with the additional param. It works as expected. Unfortunatelly php4 doesn`t have this param so this seems to be only a workaround for php5.

<?php
// only use this on windows! Linux/Unix is not affected.
$last = null;
for ($i=1;$i<=100000;$i++)
{
   $add=microtime(1);
   if ( $last !== null )
   print ($add<$last ? 'Run '.$i.' Last:'.$last.'
-Current:'.$add."\r\n" : '');
   $last=$add; 
}
?>
 [2007-08-08 08:17 UTC] jani@php.net
So this is PHP 4 only issue? Adjust the version field accordinly then.
 [2007-08-08 08:24 UTC] bjoern at xrow dot de
Well no sorry,

it is a php4 and php5 problem. What would I write down in the version field if it applies both verions? "5.2.4RC1 & 4.4.7"?

To explain again:

microtime(): doesn`t work right under php4 and php5 under windows
microtime(1): does work right under php5, it was added as a feature to php4 so it doesn`t exists in php4
 [2007-08-11 11:56 UTC] jani@php.net
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.

As you get correct results when using the optional parameter to microtime() this isn't really bug but just normal floating point issue.
And we don't add features in PHP 4 anymore..
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC