Browse Source

Time of generation of a script is calculated more correctly

Visman 8 năm trước cách đây
mục cha
commit
8e204086e7

+ 4 - 6
footer.php

@@ -145,13 +145,16 @@ else if ($footer_style == 'viewtopic')
 </div>
 </div>
 <?php
 <?php
 
 
+// End the transaction
+$db->end_transaction();
+
 // Display debug info (if enabled/defined)
 // Display debug info (if enabled/defined)
 if (defined('PUN_DEBUG'))
 if (defined('PUN_DEBUG'))
 {
 {
 	echo '<p id="debugtime">[ ';
 	echo '<p id="debugtime">[ ';
 
 
 	// Calculate script generation time
 	// Calculate script generation time
-	$time_diff = sprintf('%.3f', get_microtime() - $pun_start);
+	$time_diff = sprintf('%.3f', microtime(true) - (empty($_SERVER['REQUEST_TIME_FLOAT']) ? $pun_start : $_SERVER['REQUEST_TIME_FLOAT']));
 	echo sprintf($lang_common['Querytime'], $time_diff, $db->get_num_queries());
 	echo sprintf($lang_common['Querytime'], $time_diff, $db->get_num_queries());
 
 
 	if (function_exists('memory_get_usage'))
 	if (function_exists('memory_get_usage'))
@@ -165,10 +168,6 @@ if (defined('PUN_DEBUG'))
 	echo ' ]</p>'."\n";
 	echo ' ]</p>'."\n";
 }
 }
 
 
-
-// End the transaction
-$db->end_transaction();
-
 // Display executed queries (if enabled)
 // Display executed queries (if enabled)
 if (defined('PUN_SHOW_QUERIES'))
 if (defined('PUN_SHOW_QUERIES'))
 	display_saved_queries();
 	display_saved_queries();
@@ -178,7 +177,6 @@ $tpl_main = str_replace('<pun_footer>', $tpl_temp, $tpl_main);
 ob_end_clean();
 ob_end_clean();
 // END SUBST - <pun_footer>
 // END SUBST - <pun_footer>
 
 
-
 // Close the db connection (and free up any result data)
 // Close the db connection (and free up any result data)
 $db->close();
 $db->close();
 
 

+ 3 - 3
include/common.php

@@ -49,6 +49,9 @@ if (!defined('PUN'))
 	exit;
 	exit;
 }
 }
 
 
+// Record the start time (will be used to calculate the generation time for the page)
+$pun_start = microtime(true);
+
 // Load the functions script
 // Load the functions script
 require PUN_ROOT.'include/functions.php';
 require PUN_ROOT.'include/functions.php';
 
 
@@ -67,9 +70,6 @@ forum_unregister_globals();
 // The addon manager is responsible for storing the hook listeners and communicating with the addons
 // The addon manager is responsible for storing the hook listeners and communicating with the addons
 $flux_addons = new flux_addon_manager();
 $flux_addons = new flux_addon_manager();
 
 
-// Record the start time (will be used to calculate the generation time for the page)
-$pun_start = get_microtime();
-
 // Make sure PHP reports all errors except E_NOTICE. FluxBB supports E_ALL, but a lot of scripts it may interact with, do not
 // Make sure PHP reports all errors except E_NOTICE. FluxBB supports E_ALL, but a lot of scripts it may interact with, do not
 //error_reporting(E_ALL ^ E_NOTICE);
 //error_reporting(E_ALL ^ E_NOTICE);
 error_reporting(E_ALL);
 error_reporting(E_ALL);

+ 2 - 2
include/dblayer/mysql.php

@@ -74,7 +74,7 @@ class DBLayer
 	function query($sql, $unbuffered = false)
 	function query($sql, $unbuffered = false)
 	{
 	{
 		if (defined('PUN_SHOW_QUERIES'))
 		if (defined('PUN_SHOW_QUERIES'))
-			$q_start = get_microtime();
+			$q_start = microtime(true);
 
 
 		if ($unbuffered)
 		if ($unbuffered)
 			$this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
 			$this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
@@ -84,7 +84,7 @@ class DBLayer
 		if ($this->query_result)
 		if ($this->query_result)
 		{
 		{
 			if (defined('PUN_SHOW_QUERIES'))
 			if (defined('PUN_SHOW_QUERIES'))
-				$this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
+				$this->saved_queries[] = array($sql, sprintf('%.5f', microtime(true) - $q_start));
 
 
 			++$this->num_queries;
 			++$this->num_queries;
 
 

+ 2 - 2
include/dblayer/mysql_innodb.php

@@ -81,7 +81,7 @@ class DBLayer
 	function query($sql, $unbuffered = false)
 	function query($sql, $unbuffered = false)
 	{
 	{
 		if (defined('PUN_SHOW_QUERIES'))
 		if (defined('PUN_SHOW_QUERIES'))
-			$q_start = get_microtime();
+			$q_start = microtime(true);
 
 
 		if ($unbuffered)
 		if ($unbuffered)
 			$this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
 			$this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
@@ -91,7 +91,7 @@ class DBLayer
 		if ($this->query_result)
 		if ($this->query_result)
 		{
 		{
 			if (defined('PUN_SHOW_QUERIES'))
 			if (defined('PUN_SHOW_QUERIES'))
-				$this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
+				$this->saved_queries[] = array($sql, sprintf('%.5f', microtime(true) - $q_start));
 
 
 			++$this->num_queries;
 			++$this->num_queries;
 
 

+ 2 - 2
include/dblayer/mysqli.php

@@ -76,14 +76,14 @@ class DBLayer
 	function query($sql, $unbuffered = false)
 	function query($sql, $unbuffered = false)
 	{
 	{
 		if (defined('PUN_SHOW_QUERIES'))
 		if (defined('PUN_SHOW_QUERIES'))
-			$q_start = get_microtime();
+			$q_start = microtime(true);
 
 
 		$this->query_result = @mysqli_query($this->link_id, $sql);
 		$this->query_result = @mysqli_query($this->link_id, $sql);
 
 
 		if ($this->query_result)
 		if ($this->query_result)
 		{
 		{
 			if (defined('PUN_SHOW_QUERIES'))
 			if (defined('PUN_SHOW_QUERIES'))
-				$this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
+				$this->saved_queries[] = array($sql, sprintf('%.5f', microtime(true) - $q_start));
 
 
 			++$this->num_queries;
 			++$this->num_queries;
 
 

+ 2 - 2
include/dblayer/mysqli_innodb.php

@@ -83,14 +83,14 @@ class DBLayer
 	function query($sql, $unbuffered = false)
 	function query($sql, $unbuffered = false)
 	{
 	{
 		if (defined('PUN_SHOW_QUERIES'))
 		if (defined('PUN_SHOW_QUERIES'))
-			$q_start = get_microtime();
+			$q_start = microtime(true);
 
 
 		$this->query_result = @mysqli_query($this->link_id, $sql);
 		$this->query_result = @mysqli_query($this->link_id, $sql);
 
 
 		if ($this->query_result)
 		if ($this->query_result)
 		{
 		{
 			if (defined('PUN_SHOW_QUERIES'))
 			if (defined('PUN_SHOW_QUERIES'))
-				$this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
+				$this->saved_queries[] = array($sql, sprintf('%.5f', microtime(true) - $q_start));
 
 
 			++$this->num_queries;
 			++$this->num_queries;
 
 

+ 2 - 2
include/dblayer/pgsql.php

@@ -109,7 +109,7 @@ class DBLayer
 			$sql = preg_replace('%LIMIT ([0-9]+),([ 0-9]+)%', 'LIMIT \\2 OFFSET \\1', $sql);
 			$sql = preg_replace('%LIMIT ([0-9]+),([ 0-9]+)%', 'LIMIT \\2 OFFSET \\1', $sql);
 
 
 		if (defined('PUN_SHOW_QUERIES'))
 		if (defined('PUN_SHOW_QUERIES'))
-			$q_start = get_microtime();
+			$q_start = microtime(true);
 
 
 		@pg_send_query($this->link_id, $sql);
 		@pg_send_query($this->link_id, $sql);
 		$this->query_result = @pg_get_result($this->link_id);
 		$this->query_result = @pg_get_result($this->link_id);
@@ -117,7 +117,7 @@ class DBLayer
 		if (pg_result_status($this->query_result) != PGSQL_FATAL_ERROR)
 		if (pg_result_status($this->query_result) != PGSQL_FATAL_ERROR)
 		{
 		{
 			if (defined('PUN_SHOW_QUERIES'))
 			if (defined('PUN_SHOW_QUERIES'))
-				$this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
+				$this->saved_queries[] = array($sql, sprintf('%.5f', microtime(true) - $q_start));
 
 
 			++$this->num_queries;
 			++$this->num_queries;
 
 

+ 2 - 2
include/dblayer/sqlite.php

@@ -95,7 +95,7 @@ class DBLayer
 	function query($sql, $unbuffered = false)
 	function query($sql, $unbuffered = false)
 	{
 	{
 		if (defined('PUN_SHOW_QUERIES'))
 		if (defined('PUN_SHOW_QUERIES'))
-			$q_start = get_microtime();
+			$q_start = microtime(true);
 
 
 		if ($unbuffered)
 		if ($unbuffered)
 			$this->query_result = @sqlite_unbuffered_query($this->link_id, $sql);
 			$this->query_result = @sqlite_unbuffered_query($this->link_id, $sql);
@@ -105,7 +105,7 @@ class DBLayer
 		if ($this->query_result)
 		if ($this->query_result)
 		{
 		{
 			if (defined('PUN_SHOW_QUERIES'))
 			if (defined('PUN_SHOW_QUERIES'))
-				$this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
+				$this->saved_queries[] = array($sql, sprintf('%.5f', microtime(true) - $q_start));
 
 
 			++$this->num_queries;
 			++$this->num_queries;
 
 

+ 0 - 10
include/functions.php

@@ -7,16 +7,6 @@
  */
  */
 
 
 
 
-
-//
-// Return current timestamp (with microseconds) as a float
-//
-function get_microtime()
-{
-	list($usec, $sec) = explode(' ', microtime());
-	return ((float)$usec + (float)$sec);
-}
-
 //
 //
 // Cookie stuff!
 // Cookie stuff!
 //
 //

+ 4 - 4
include/srand.php

@@ -111,12 +111,12 @@ function secure_random_bytes($len = 10)
          // Measure the time that the operations will take on average
          // Measure the time that the operations will take on average
          for ($i = 0; $i < 3; $i++) 
          for ($i = 0; $i < 3; $i++) 
          {
          {
-            $c1 = get_microtime();
+            $c1 = microtime(true);
             $var = sha1(mt_rand());
             $var = sha1(mt_rand());
             for ($j = 0; $j < 50; $j++) {
             for ($j = 0; $j < 50; $j++) {
                $var = sha1($var);
                $var = sha1($var);
             }
             }
-            $c2 = get_microtime();
+            $c2 = microtime(true);
             $entropy .= $c1 . $c2;
             $entropy .= $c1 . $c2;
          }
          }
 
 
@@ -129,12 +129,12 @@ function secure_random_bytes($len = 10)
          $iter = $bytes * (int) (ceil(8 / $bits_per_round));
          $iter = $bytes * (int) (ceil(8 / $bits_per_round));
          for ($i = 0; $i < $iter; $i++)
          for ($i = 0; $i < $iter; $i++)
          {
          {
-            $c1 = get_microtime();
+            $c1 = microtime(true);
             $var = sha1(mt_rand());
             $var = sha1(mt_rand());
             for ($j = 0; $j < $rounds; $j++) {
             for ($j = 0; $j < $rounds; $j++) {
                $var = sha1($var);
                $var = sha1($var);
             }
             }
-            $c2 = get_microtime();
+            $c2 = microtime(true);
             $entropy .= $c1 . $c2;
             $entropy .= $c1 . $c2;
          }
          }