Anonymous | Login | Signup for a new account | 12-17-2024 14:59 PST |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ View Advanced ] [ 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 | ||||||
Status | closed | Product 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); |
||||||||
Additional Information | |||||||||
Attached Files | |||||||||
|
Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed. 26 unique queries executed. |