Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003285 [Quercus] block always 01-19-09 09:18 01-21-09 16:06
Reporter koreth View Status public  
Assigned To nam
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 4.0.0 Product Version 4.0.0
  Product Build
Summary 0003285: microtime(true) clock discontinuity
Description <?php
$a = microtime(true);
usleep(500000);
print microtime(true) - $a;

Regular PHP always prints a value around 0.5. But if you load it multiple times under Quercus, you will variously get values around 0.5, 1.5, and -0.5.

Patch:

--- a/modules/quercus/src/com/caucho/quercus/lib/date/DateModule.java
+++ b/modules/quercus/src/com/caucho/quercus/lib/date/DateModule.java
@@ -844,18 +844,25 @@ public class DateModule extends AbstractQuercusModule {
     return value;
   }
 
+ static double initialMillisecTime = -1;
+ static long initialNanosecTime = -1;
+
   /**
    * Returns the time including microseconds
    */
   public static Value microtime(Env env, @Optional boolean getAsFloat)
   {
- long sec = Alarm.getExactTime() / 1000;
- long nanos = Alarm.getExactTimeNanoseconds() % 1000000000L;
-
- if (nanos < 0)
- nanos += 1000000000;
+ // Since nanosec time is not based on the same epoch as system time,
+ // figure out what system time corresponds to the current nanosec time.
+ // Then we can use that system time as a basis to return real system
+ // times based on the nanosec time in subsequent calls.
+ if (initialNanosecTime == -1) {
+ initialMillisecTime = Alarm.getExactTime() * .001;
+ initialNanosecTime = Alarm.getExactTimeNanoseconds();
+ }
 
- double now = sec + nanos * 1e-9;
+ long nanos = Alarm.getExactTimeNanoseconds();
+ double now = (nanos - initialNanosecTime) * 1e-9 + initialMillisecTime;
 
     if (getAsFloat) {
       return new DoubleValue(now);
Steps To Reproduce
Additional Information
Attached Files

- Relationships

- Notes
(0003769)
nam
01-21-09 16:06

php/190v
 

- Issue History
Date Modified Username Field Change
01-19-09 09:18 koreth New Issue
01-20-09 15:31 nam Status new => assigned
01-20-09 15:31 nam Assigned To  => nam
01-21-09 16:06 nam Status assigned => closed
01-21-09 16:06 nam Note Added: 0003769
01-21-09 16:06 nam Resolution open => fixed
01-21-09 16:06 nam Fixed in Version  => 4.0.0


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed.
26 unique queries executed.
Powered by Mantis Bugtracker