Bug #54050 [Opn->Dup]: microtime() returns random values
| From: | sixd@php.net | Date: | Mon, 11 Mar 2013 20:56:37 +0000 |
| Subject: | Bug #54050 [Opn->Dup]: microtime() returns random values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-177739@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54050&edit=1
ID: 54050
Updated by: sixd@php.net
Reported by: nospam at unclassified dot de
Summary: microtime() returns random values
-Status: Open
+Status: Duplicate
Type: Bug
Package: *General Issues
Operating System: Windows XP
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #64370
Previous Comments:
------------------------------------------------------------------------
[2011-06-09 13:51:32] ynn at free dot fr
There is a simpler test case :
for ($i=0 ; $i<=100000 ; $i++)
{
$mt = microtime(true);
if(isset($last) && $mt<$last)
echo 'Last:'.$last.' - Current:'.$mt."\n";
$last = $mt;
}
On Windows XP, PHP 5.3.5, I get outputs that looks like :
Last:1307620010.9549 - Current:1307620010.0533
Last:1307620010.9742 - Current:1307620010.0689
Last:1307620010.9742 - Current:1307620010.0689
Last:1307620010.983 - Current:1307620010.0845
Last:1307620010.9909 - Current:1307620010.0845
Last:1307620011.0142 - Current:1307620010.1158
Last:1307620011.0612 - Current:1307620010.147
Last:1307620011.0679 - Current:1307620010.1626
Last:1307620011.0865 - Current:1307620010.1783
Last:1307620011.115 - Current:1307620010.2095
------------------------------------------------------------------------
[2011-02-18 23:31:48] nospam at unclassified dot de
The seconds part of the return value seems to be my system boot time. I have now restarted the
computer and the value points to that time. The fractional part is kind of oscillating around
similar values. It's going up and down a bit every time but it has the tendency to decrease
slowly. I have discovered a few other places in my application where it happens. But it's
always the same database function. The same code.
$start0 = microtime(true);
$start = microtime(true);
if (abs($start - $start0) > 1)
{
var_dump($start0);
var_dump($start);
}
This should never print something but it does. Here are a few examples:
float(1298065510.0493) float(1298068208.1106)
float(1298065510.0533) float(1298068218.7475)
float(1298065510.0405) float(1298068225.1549)
float(1298065510.038) float(1298068231.7615)
float(1298065510.0269) float(1298068237.0667)
float(1298065510.0234) float(1298068244.8534)
float(1298065510.0266) float(1298068250.9826)
float(1298065510.0145) float(1298068257.6404)
float(1298065510.8087) float(1298068265.3026)
float(1298065510.809) float(1298068271.1601)
float(1298065510.8087) float(1298068277.0327)
float(1298065510.8029) float(1298068284.6319)
...
------------------------------------------------------------------------
[2011-02-18 22:32:24] nospam at unclassified dot de
I have restarted the Apache web server and then the microtime function worked correctly in this
situation a few times. Then it started to produce the same bogus data often. Now the original
problem is right here again. Same place. Only the approximately 100th of like 200 times it is
called. Instead of 1298064639.9228 (or similar) as everywhere else on the page it returns values
around 1296908080.167 or 1296908081.2987. Quite a bit off but relatively "constant".
------------------------------------------------------------------------
[2011-02-18 22:17:00] nospam at unclassified dot de
Description:
------------
I have a very weird bug here. The microtime() function with the parameter true works fine everywhere
in my entire application - except in one single place. It's measuring database query durations
here. It counts everything perfectly but always at a certain database query in the deepest middle of
my application it returns random values. When I call it a second time just a line of code later, it
returns the correct value again. It happens every time tonight. I cannot provide a testcase yet
because there's another tens of thousands of lines of code hanging at this to work at all.
I cannot upgrade PHP because there's no newer XAMPP package available. Version is 5.3.1.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54050&edit=1