Mantis - Quercus
|
|||||
Viewing Issue Advanced Details | |||||
|
|||||
ID: | Category: | Severity: | Reproducibility: | Date Submitted: | Last Update: |
3285 | block | always | 01-19-09 09:18 | 01-21-09 16:06 | |
|
|||||
Reporter: | koreth | Platform: | |||
Assigned To: | nam | OS: | |||
Priority: | normal | OS Version: | |||
Status: | closed | Product Version: | 4.0.0 | ||
Product Build: | Resolution: | fixed | |||
Projection: | none | ||||
ETA: | none | Fixed in Version: | 4.0.0 | ||
|
|||||
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: | |||||
Relationships | |||||
Attached Files: |
Notes | |||||
|
|||||
|
|