Permalink
Browse files

Do not rely on $_SERVER['REQUEST_TIME'] to be available.

  • Loading branch information...
1 parent 75fb13e commit 79ffae59bffc0adb9181acf9411dd3e0b727c68f @sebastianbergmann committed Sep 7, 2011
Showing with 12 additions and 1 deletion.
  1. +12 −1 PHP/Timer.php
View
@@ -63,6 +63,11 @@ class PHP_Timer
protected static $startTimes = array();
/**
+ * @var float
+ */
+ public static $requestTime;
+
+ /**
* Starts the timer.
*/
public static function start()
@@ -123,7 +128,7 @@ public static function secondsToTimeString($time)
*/
public static function timeSinceStartOfRequest()
{
- return self::secondsToTimeString(time() - $_SERVER['REQUEST_TIME']);
+ return self::secondsToTimeString(time() - self::$requestTime);
}
/**
@@ -140,3 +145,9 @@ public static function resourceUsage()
);
}
}
+
+if (isset($_SERVER['REQUEST_TIME'])) {
+ PHP_Timer::$requestTime = $_SERVER['REQUEST_TIME'];
+} else {
+ PHP_Timer::$requestTime = time();
+}

0 comments on commit 79ffae5

Please sign in to comment.