From 1a91aaa8827b6a3135ad4963263fd9e19cd5ead3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 29 Jun 2016 20:39:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88microtime=5Ffloat=E5=87=BD?= =?UTF-8?q?=E6=95=B0=20=E5=8F=96=E6=B6=88MODE=5FPATH=20IS=5FAPI=E5=B8=B8?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 10 +------ library/think/debug/trace/Console.php | 39 +++++++++++++-------------- library/think/debug/trace/Html.php | 3 +-- library/think/log/driver/File.php | 4 +-- library/think/log/driver/Sae.php | 4 +-- library/think/log/driver/Socket.php | 2 +- tests/thinkphp/baseTest.php | 2 -- 7 files changed, 26 insertions(+), 38 deletions(-) diff --git a/base.php b/base.php index 9bbf8ff2..78b3f920 100644 --- a/base.php +++ b/base.php @@ -8,20 +8,14 @@ // +---------------------------------------------------------------------- // | Author: liu21st // +---------------------------------------------------------------------- -function microtime_float() -{ - list ($usec, $sec) = explode(" ", microtime()); - return (( float )$usec + ( float )$sec); -} define('THINK_VERSION', '5.0.0 RC3'); -define('START_TIME', microtime_float()); +define('START_TIME', number_format(microtime(true), 8, '.', '')); define('START_MEM', memory_get_usage()); define('EXT', '.php'); define('DS', DIRECTORY_SEPARATOR); defined('THINK_PATH') or define('THINK_PATH', __DIR__ . DS); define('LIB_PATH', THINK_PATH . 'library' . DS); -define('MODE_PATH', THINK_PATH . 'mode' . DS); // 系统应用模式目录 define('CORE_PATH', LIB_PATH . 'think' . DS); define('TRAIT_PATH', LIB_PATH . 'traits' . DS); defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS); @@ -35,8 +29,6 @@ defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS); defined('CONF_PATH') or define('CONF_PATH', APP_PATH); // 配置文件目录 defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀 defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_'); // 环境变量的配置前缀 -defined('IS_API') or define('IS_API', false); // 是否API接口 -defined('AUTO_SCAN_PACKAGE') or define('AUTO_SCAN_PACKAGE', false); // 是否自动扫描非Composer安装类库 // 环境常量 define('IS_CLI', PHP_SAPI == 'cli' ? true : false); diff --git a/library/think/debug/trace/Console.php b/library/think/debug/trace/Console.php index 7bf8d831..596486b7 100644 --- a/library/think/debug/trace/Console.php +++ b/library/think/debug/trace/Console.php @@ -15,7 +15,6 @@ use think\Cache; use think\Config; use think\Db; use think\Debug; -use think\Request; /** * 浏览器调试输出 @@ -43,7 +42,7 @@ class Console public function output(array $log = []) { // 获取基本信息 - $runtime = microtime_float() - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; $reqs = number_format(1 / $runtime, 2); $mem = number_format((memory_get_usage() - START_MEM) / 1024, 2); @@ -106,38 +105,38 @@ JS; { $type = strtolower($type); $trace_tabs = array_values($this->config['trace_tabs']); - $line[] = ($type == $trace_tabs[0] || '调试' == $type || '错误'== $type) - ? "console.group('{$type}');" - : "console.groupCollapsed('{$type}');"; + $line[] = ($type == $trace_tabs[0] || '调试' == $type || '错误' == $type) + ? "console.group('{$type}');" + : "console.groupCollapsed('{$type}');"; - foreach ((array)$msg as $key => $m) { + foreach ((array) $msg as $key => $m) { switch ($type) { case '调试': $var_type = gettype($m); - if(in_array($var_type, ['array', 'string'])){ - $line[] = "console.log(".json_encode($m).");"; - }else{ - $line[] = "console.log(".json_encode(var_export($m, 1)).");"; + if (in_array($var_type, ['array', 'string'])) { + $line[] = "console.log(" . json_encode($m) . ");"; + } else { + $line[] = "console.log(" . json_encode(var_export($m, 1)) . ");"; } break; case '错误': - $msg = str_replace(PHP_EOL, '\n', $m); - $style = 'color:#F4006B;font-size:14px;'; - $line[] = "console.error(\"%c{$msg}\", \"{$style}\");"; + $msg = str_replace(PHP_EOL, '\n', $m); + $style = 'color:#F4006B;font-size:14px;'; + $line[] = "console.error(\"%c{$msg}\", \"{$style}\");"; break; case 'sql': - $msg = str_replace(PHP_EOL, '\n', $m); - $style = "color:#009bb4;"; - $line[] = "console.log(\"%c{$msg}\", \"{$style}\");"; + $msg = str_replace(PHP_EOL, '\n', $m); + $style = "color:#009bb4;"; + $line[] = "console.log(\"%c{$msg}\", \"{$style}\");"; break; default: - $m = is_string($key)? $key . ' ' . $m : $key+1 . ' ' . $m; - $msg = json_encode($m); - $line[] = "console.log({$msg});"; + $m = is_string($key) ? $key . ' ' . $m : $key + 1 . ' ' . $m; + $msg = json_encode($m); + $line[] = "console.log({$msg});"; break; } } - $line[]= "console.groupEnd();"; + $line[] = "console.groupEnd();"; return implode(PHP_EOL, $line); } diff --git a/library/think/debug/trace/Html.php b/library/think/debug/trace/Html.php index 518f0bc5..f5b8e724 100644 --- a/library/think/debug/trace/Html.php +++ b/library/think/debug/trace/Html.php @@ -15,7 +15,6 @@ use think\Cache; use think\Config; use think\Db; use think\Debug; -use think\Request; /** * 页面Trace调试 @@ -44,7 +43,7 @@ class Html { // 获取基本信息 - $runtime = microtime_float() - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; $reqs = number_format(1 / $runtime, 2); $mem = number_format((memory_get_usage() - START_MEM) / 1024, 2); diff --git a/library/think/log/driver/File.php b/library/think/log/driver/File.php index 78d5dc30..76ade7ee 100644 --- a/library/think/log/driver/File.php +++ b/library/think/log/driver/File.php @@ -54,7 +54,7 @@ class File } else { $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); } - $runtime = microtime_float() - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; $reqs = number_format(1 / $runtime, 2); $time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]"; $memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2); @@ -66,7 +66,7 @@ class File foreach ($val as $msg) { if (!is_string($msg)) { $msg = var_export($msg, true); - } + } $info .= '[ ' . $type . ' ] ' . $msg . "\r\n"; } } diff --git a/library/think/log/driver/Sae.php b/library/think/log/driver/Sae.php index 17a41594..a45f3a62 100644 --- a/library/think/log/driver/Sae.php +++ b/library/think/log/driver/Sae.php @@ -33,7 +33,7 @@ class Sae } else { $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); } - $runtime = microtime_float() - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; $reqs = number_format(1 / $runtime, 2); $time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]"; $memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2); @@ -45,7 +45,7 @@ class Sae foreach ($val as $msg) { if (!is_string($msg)) { $msg = var_export($msg, true); - } + } $info .= '[ ' . $type . ' ] ' . $msg . "\r\n"; } } diff --git a/library/think/log/driver/Socket.php b/library/think/log/driver/Socket.php index 5336853d..2d423a5d 100644 --- a/library/think/log/driver/Socket.php +++ b/library/think/log/driver/Socket.php @@ -65,7 +65,7 @@ class Socket if (!$this->check()) { return false; } - $runtime = microtime_float() - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; $reqs = number_format(1 / number_format($runtime, 8), 2); $time_str = " [运行时间:{$runtime}s][吞吐率:{$reqs}req/s]"; $memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2); diff --git a/tests/thinkphp/baseTest.php b/tests/thinkphp/baseTest.php index 1c066bea..3106a139 100644 --- a/tests/thinkphp/baseTest.php +++ b/tests/thinkphp/baseTest.php @@ -23,7 +23,6 @@ class baseTest extends \PHPUnit_Framework_TestCase $this->assertNotEmpty(THINK_PATH); $this->assertNotEmpty(LIB_PATH); $this->assertNotEmpty(EXTEND_PATH); - $this->assertNotEmpty(MODE_PATH); $this->assertNotEmpty(CORE_PATH); $this->assertNotEmpty(TRAIT_PATH); $this->assertNotEmpty(APP_PATH); @@ -34,7 +33,6 @@ class baseTest extends \PHPUnit_Framework_TestCase $this->assertNotEmpty(VENDOR_PATH); $this->assertNotEmpty(EXT); $this->assertNotEmpty(ENV_PREFIX); - $this->assertTrue(is_bool(IS_API)); $this->assertTrue(!is_null(IS_WIN)); $this->assertTrue(!is_null(IS_CLI)); }