Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fd284bc

Browse files
GrahamCampbellnicolas-grekas
authored andcommitted
Ensure hrtime is monotonic
1 parent c09df60 commit fd284bc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

‎Php73.php‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,28 @@ final class Php73
2121
{
2222
public static $startAt = 1533462603;
2323

24+
private static $previousValue = '0';
25+
2426
/**
2527
* @param bool $asNum
2628
*
2729
* @return array|float|int
2830
*/
2931
public static function hrtime($asNum = false)
3032
{
31-
$ns = microtime(false);
32-
$s = substr($ns, 11) - self::$startAt;
33-
$ns = 1E9 * (float) $ns;
33+
$microtime = microtime(false);
34+
$current = 1E9 * (float) $microtime;
35+
$previous = 1E9 * (float) self::$previousValue;
36+
37+
if ($current >= $previous) {
38+
$ns = $current;
39+
self::$previousValue = $microtime;
40+
} else {
41+
$ns = $previous;
42+
$microtime = self::$previousValue;
43+
}
44+
45+
$s = substr($microtime, 11) - self::$startAt;
3446

3547
if ($asNum) {
3648
$ns += $s * 1E9;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /