内核更新,多余文件清理

This commit is contained in:
2016-07-01 18:04:46 +08:00
parent a595f3a13e
commit 0398e5bd80
31 changed files with 426 additions and 551 deletions
+3 -3
View File
@@ -9,9 +9,9 @@
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
define('THINK_VERSION', '5.0.0 RC3');
define('START_TIME', number_format(microtime(true), 8, '.', ''));
define('START_MEM', memory_get_usage());
define('THINK_VERSION', '5.0.0 RC4');
define('THINK_START_TIME', number_format(microtime(true), 8, '.', ''));
define('THINK_START_MEM', memory_get_usage());
define('EXT', '.php');
define('DS', DIRECTORY_SEPARATOR);
defined('THINK_PATH') or define('THINK_PATH', __DIR__ . DS);
+2 -2
View File
@@ -140,7 +140,7 @@ return [
// +----------------------------------------------------------------------
'log' => [
// 日志记录方式,支持 file socket sae
// 日志记录方式,支持 file sae
'type' => 'File',
// 日志保存目录
'path' => LOG_PATH,
@@ -150,7 +150,7 @@ return [
// | Trace设置
// +----------------------------------------------------------------------
'trace' => [
//支持Html,Console 设为false则不显示
// 支持Html Socket Console 设为false则不显示
'type' => false,
],
+215 -159
View File
@@ -33,9 +33,11 @@ use think\View;
* @param string $ext 类库后缀
* @return boolean
*/
function load_trait($class, $ext = EXT)
{
return Loader::import($class, TRAIT_PATH, $ext);
if (!function_exists('load_trait')) {
function load_trait($class, $ext = EXT)
{
return Loader::import($class, TRAIT_PATH, $ext);
}
}
/**
@@ -47,10 +49,12 @@ function load_trait($class, $ext = EXT)
*
* @throws Exception
*/
function exception($msg, $code = 0, $exception = '')
{
$e = $exception ?: '\think\Exception';
throw new $e($msg, $code);
if (!function_exists('exception')) {
function exception($msg, $code = 0, $exception = '')
{
$e = $exception ?: '\think\Exception';
throw new $e($msg, $code);
}
}
/**
@@ -60,12 +64,14 @@ function exception($msg, $code = 0, $exception = '')
* @param integer|string $dec 小数位 如果是m 表示统计内存占用
* @return mixed
*/
function debug($start, $end = '', $dec = 6)
{
if ('' == $end) {
Debug::remark($start);
} else {
return 'm' == $dec ? Debug::getRangeMem($start, $end) : Debug::getRangeTime($start, $end, $dec);
if (!function_exists('debug')) {
function debug($start, $end = '', $dec = 6)
{
if ('' == $end) {
Debug::remark($start);
} else {
return 'm' == $dec ? Debug::getRangeMem($start, $end) : Debug::getRangeTime($start, $end, $dec);
}
}
}
@@ -76,9 +82,11 @@ function debug($start, $end = '', $dec = 6)
* @param string $lang 语言
* @return mixed
*/
function lang($name, $vars = [], $lang = '')
{
return Lang::get($name, $vars, $lang);
if (!function_exists('lang')) {
function lang($name, $vars = [], $lang = '')
{
return Lang::get($name, $vars, $lang);
}
}
/**
@@ -88,12 +96,14 @@ function lang($name, $vars = [], $lang = '')
* @param string $range 作用域
* @return mixed
*/
function config($name = '', $value = null, $range = '')
{
if (is_null($value) && is_string($name)) {
return Config::get($name, $range);
} else {
return Config::set($name, $value, $range);
if (!function_exists('config')) {
function config($name = '', $value = null, $range = '')
{
if (is_null($value) && is_string($name)) {
return Config::get($name, $range);
} else {
return Config::set($name, $value, $range);
}
}
}
@@ -104,28 +114,30 @@ function config($name = '', $value = null, $range = '')
* @param string $filter 过滤方法
* @return mixed
*/
function input($key, $default = null, $filter = null)
{
if (0 === strpos($key, '?')) {
$key = substr($key, 1);
$has = true;
}
if ($pos = strpos($key, '.')) {
// 指定参数来源
$method = substr($key, 0, $pos);
if (in_array($method, ['get', 'post', 'put', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
$key = substr($key, $pos + 1);
if (!function_exists('input')) {
function input($key, $default = null, $filter = null)
{
if (0 === strpos($key, '?')) {
$key = substr($key, 1);
$has = true;
}
if ($pos = strpos($key, '.')) {
// 指定参数来源
$method = substr($key, 0, $pos);
if (in_array($method, ['get', 'post', 'put', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
$key = substr($key, $pos + 1);
} else {
$method = 'param';
}
} else {
// 默认为自动判断
$method = 'param';
}
} else {
// 默认为自动判断
$method = 'param';
}
if (isset($has)) {
return request()->has($key, $method, $default);
} else {
return request()->$method($key, $default, $filter);
if (isset($has)) {
return request()->has($key, $method, $default);
} else {
return request()->$method($key, $default, $filter);
}
}
}
@@ -135,9 +147,11 @@ function input($key, $default = null, $filter = null)
* @param array $data 传人的参数
* @return mixed
*/
function widget($name, $data = [])
{
return Loader::action($name, $data, 'widget');
if (!function_exists('widget')) {
function widget($name, $data = [])
{
return Loader::action($name, $data, 'widget');
}
}
/**
@@ -147,9 +161,11 @@ function widget($name, $data = [])
* @param bool $appendSuffix 是否添加类名后缀
* @return \think\Model
*/
function model($name = '', $layer = 'model', $appendSuffix = false)
{
return Loader::model($name, $layer, $appendSuffix);
if (!function_exists('model')) {
function model($name = '', $layer = 'model', $appendSuffix = false)
{
return Loader::model($name, $layer, $appendSuffix);
}
}
/**
@@ -159,9 +175,11 @@ function model($name = '', $layer = 'model', $appendSuffix = false)
* @param bool $appendSuffix 是否添加类名后缀
* @return \think\Validate
*/
function validate($name = '', $layer = 'validate', $appendSuffix = false)
{
return Loader::validate($name, $layer, $appendSuffix);
if (!function_exists('validate')) {
function validate($name = '', $layer = 'validate', $appendSuffix = false)
{
return Loader::validate($name, $layer, $appendSuffix);
}
}
/**
@@ -170,9 +188,11 @@ function validate($name = '', $layer = 'validate', $appendSuffix = false)
* @param array|string $config 数据库配置参数
* @return \think\db\Query
*/
function db($name = '', $config = [])
{
return Db::connect($config)->name($name);
if (!function_exists('db')) {
function db($name = '', $config = [])
{
return Db::connect($config)->name($name);
}
}
/**
@@ -182,9 +202,11 @@ function db($name = '', $config = [])
* @param bool $appendSuffix 是否添加类名后缀
* @return \think\Controller
*/
function controller($name, $layer = 'controller', $appendSuffix = false)
{
return Loader::controller($name, $layer, $appendSuffix);
if (!function_exists('controller')) {
function controller($name, $layer = 'controller', $appendSuffix = false)
{
return Loader::controller($name, $layer, $appendSuffix);
}
}
/**
@@ -195,9 +217,11 @@ function controller($name, $layer = 'controller', $appendSuffix = false)
* @param bool $appendSuffix 是否添加类名后缀
* @return mixed
*/
function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
{
return Loader::action($url, $vars, $layer, $appendSuffix);
if (!function_exists('action')) {
function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
{
return Loader::action($url, $vars, $layer, $appendSuffix);
}
}
/**
@@ -207,9 +231,11 @@ function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
* @param string $ext 导入的文件扩展名
* @return boolean
*/
function import($class, $baseUrl = '', $ext = EXT)
{
return Loader::import($class, $baseUrl, $ext);
if (!function_exists('import')) {
function import($class, $baseUrl = '', $ext = EXT)
{
return Loader::import($class, $baseUrl, $ext);
}
}
/**
@@ -218,9 +244,11 @@ function import($class, $baseUrl = '', $ext = EXT)
* @param string $ext 类库后缀
* @return boolean
*/
function vendor($class, $ext = EXT)
{
return Loader::import($class, VENDOR_PATH, $ext);
if (!function_exists('vendor')) {
function vendor($class, $ext = EXT)
{
return Loader::import($class, VENDOR_PATH, $ext);
}
}
/**
@@ -230,9 +258,11 @@ function vendor($class, $ext = EXT)
* @param string $label 标签 默认为空
* @return void|string
*/
function dump($var, $echo = true, $label = null)
{
return Debug::dump($var, $echo, $label);
if (!function_exists('dump')) {
function dump($var, $echo = true, $label = null)
{
return Debug::dump($var, $echo, $label);
}
}
/**
@@ -243,9 +273,11 @@ function dump($var, $echo = true, $label = null)
* @param bool|string $domain 域名
* @return string
*/
function url($url = '', $vars = '', $suffix = true, $domain = false)
{
return Url::build($url, $vars, $suffix, $domain);
if (!function_exists('url')) {
function url($url = '', $vars = '', $suffix = true, $domain = false)
{
return Url::build($url, $vars, $suffix, $domain);
}
}
/**
@@ -255,23 +287,25 @@ function url($url = '', $vars = '', $suffix = true, $domain = false)
* @param string $prefix 前缀
* @return mixed
*/
function session($name, $value = '', $prefix = null)
{
if (is_array($name)) {
// 初始化
Session::init($name);
} elseif (is_null($name)) {
// 清除
Session::clear($value);
} elseif ('' === $value) {
// 判断或获取
return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix);
} elseif (is_null($value)) {
// 删除
return Session::delete($name, $prefix);
} else {
// 设置
return Session::set($name, $value, $prefix);
if (!function_exists('session')) {
function session($name, $value = '', $prefix = null)
{
if (is_array($name)) {
// 初始化
Session::init($name);
} elseif (is_null($name)) {
// 清除
Session::clear($value);
} elseif ('' === $value) {
// 判断或获取
return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix);
} elseif (is_null($value)) {
// 删除
return Session::delete($name, $prefix);
} else {
// 设置
return Session::set($name, $value, $prefix);
}
}
}
@@ -282,23 +316,25 @@ function session($name, $value = '', $prefix = null)
* @param mixed $option 参数
* @return mixed
*/
function cookie($name, $value = '', $option = null)
{
if (is_array($name)) {
// 初始化
Cookie::init($name);
} elseif (is_null($name)) {
// 清除
Cookie::clear($value);
} elseif ('' === $value) {
// 获取
return Cookie::get($name);
} elseif (is_null($value)) {
// 删除
return Cookie::delete($name);
} else {
// 设置
return Cookie::set($name, $value, $option);
if (!function_exists('cookie')) {
function cookie($name, $value = '', $option = null)
{
if (is_array($name)) {
// 初始化
Cookie::init($name);
} elseif (is_null($name)) {
// 清除
Cookie::clear($value);
} elseif ('' === $value) {
// 获取
return Cookie::get($name);
} elseif (is_null($value)) {
// 删除
return Cookie::delete($name);
} else {
// 设置
return Cookie::set($name, $value, $option);
}
}
}
@@ -309,29 +345,31 @@ function cookie($name, $value = '', $option = null)
* @param mixed $options 缓存参数
* @return mixed
*/
function cache($name, $value = '', $options = null)
{
if (is_array($options)) {
// 缓存操作的同时初始化
Cache::connect($options);
} elseif (is_array($name)) {
// 缓存初始化
return Cache::connect($name);
}
if ('' === $value) {
// 获取缓存
return Cache::get($name);
} elseif (is_null($value)) {
// 删除缓存
return Cache::rm($name);
} else {
// 缓存数据
if (!function_exists('cache')) {
function cache($name, $value = '', $options = null)
{
if (is_array($options)) {
$expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间
} else {
$expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间
// 缓存操作的同时初始化
Cache::connect($options);
} elseif (is_array($name)) {
// 缓存初始化
return Cache::connect($name);
}
if ('' === $value) {
// 获取缓存
return Cache::get($name);
} elseif (is_null($value)) {
// 删除缓存
return Cache::rm($name);
} else {
// 缓存数据
if (is_array($options)) {
$expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间
} else {
$expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间
}
return Cache::set($name, $value, $expire);
}
return Cache::set($name, $value, $expire);
}
}
@@ -341,12 +379,14 @@ function cache($name, $value = '', $options = null)
* @param string $level 日志级别
* @return void|array
*/
function trace($log = '[think]', $level = 'log')
{
if ('[think]' === $log) {
return Log::getLog();
} else {
Log::record($log, $level);
if (!function_exists('trace')) {
function trace($log = '[think]', $level = 'log')
{
if ('[think]' === $log) {
return Log::getLog();
} else {
Log::record($log, $level);
}
}
}
@@ -354,9 +394,11 @@ function trace($log = '[think]', $level = 'log')
* 获取当前Request对象实例
* @return Request
*/
function request()
{
return Request::instance();
if (!function_exists('request')) {
function request()
{
return Request::instance();
}
}
/**
@@ -367,9 +409,11 @@ function request()
* @param string $type
* @return Response
*/
function response($data = [], $code = 200, $header = [], $type = 'html')
{
return Response::create($data, $type, $code, $header);
if (!function_exists('response')) {
function response($data = [], $code = 200, $header = [], $type = 'html')
{
return Response::create($data, $type, $code, $header);
}
}
/**
@@ -379,9 +423,11 @@ function response($data = [], $code = 200, $header = [], $type = 'html')
* @param integer $code 状态码
* @return \think\response\View
*/
function view($template = '', $vars = [], $code = 200)
{
return Response::create($template, 'view', $code)->vars($vars);
if (!function_exists('view')) {
function view($template = '', $vars = [], $code = 200)
{
return Response::create($template, 'view', $code)->vars($vars);
}
}
/**
@@ -392,9 +438,11 @@ function view($template = '', $vars = [], $code = 200)
* @param array $options 参数
* @return \think\response\Json
*/
function json($data = [], $code = 200, $header = [], $options = [])
{
return Response::create($data, 'json', $code, $header, $options);
if (!function_exists('json')) {
function json($data = [], $code = 200, $header = [], $options = [])
{
return Response::create($data, 'json', $code, $header, $options);
}
}
/**
@@ -405,9 +453,11 @@ function json($data = [], $code = 200, $header = [], $options = [])
* @param array $options 参数
* @return \think\response\Jsonp
*/
function jsonp($data = [], $code = 200, $header = [], $options = [])
{
return Response::create($data, 'jsonp', $code, $header, $options);
if (!function_exists('jsonp')) {
function jsonp($data = [], $code = 200, $header = [], $options = [])
{
return Response::create($data, 'jsonp', $code, $header, $options);
}
}
/**
@@ -418,9 +468,11 @@ function jsonp($data = [], $code = 200, $header = [], $options = [])
* @param array $options 参数
* @return \think\response\Xml
*/
function xml($data = [], $code = 200, $header = [], $options = [])
{
return Response::create($data, 'xml', $code, $header, $options);
if (!function_exists('xml')) {
function xml($data = [], $code = 200, $header = [], $options = [])
{
return Response::create($data, 'xml', $code, $header, $options);
}
}
/**
@@ -430,13 +482,15 @@ function xml($data = [], $code = 200, $header = [], $options = [])
* @param integer $code 状态码
* @return \think\response\Redirect
*/
function redirect($url = [], $params = [], $code = 302)
{
if (is_integer($params)) {
$code = $params;
$params = [];
if (!function_exists('redirect')) {
function redirect($url = [], $params = [], $code = 302)
{
if (is_integer($params)) {
$code = $params;
$params = [];
}
return Response::create($url, 'redirect', $code)->params($params);
}
return Response::create($url, 'redirect', $code)->params($params);
}
/**
@@ -445,7 +499,9 @@ function redirect($url = [], $params = [], $code = 302)
* @param string $message 错误信息
* @param array $header 参数
*/
function abort($code, $message = null, $header = [])
{
throw new \think\exception\HttpException($code, $message, null, $header);
if (!function_exists('abort')) {
function abort($code, $message = null, $header = [])
{
throw new \think\exception\HttpException($code, $message, null, $header);
}
}
+5 -7
View File
@@ -12,7 +12,6 @@
namespace think;
use think\Config;
use think\debug\Trace;
use think\Exception;
use think\exception\HttpException;
use think\exception\HttpResponseException;
@@ -145,19 +144,18 @@ class App
$response = $data;
} elseif (!is_null($data)) {
// 默认自动识别响应输出类型
$isAjax = $request->isAjax();
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
$isAjax = $request->isAjax();
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
$response = Response::create($data, $type);
} else {
$response = Response::create();
}
// 监听app_end
Hook::listen('app_end', $response);
//注入Trace
self::$debug && Trace::inject($response);
// Trace调试注入
Debug::inject($response);
return $response;
}
+48 -2
View File
@@ -11,6 +11,13 @@
namespace think;
use think\Config;
use think\exception\ClassNotFoundException;
use think\Log;
use think\Request;
use think\Response;
use think\response\Redirect;
class Debug
{
// 区间时间信息
@@ -56,7 +63,7 @@ class Debug
*/
public static function getUseTime($dec = 6)
{
return number_format((microtime(true) - START_TIME), $dec);
return number_format((microtime(true) - THINK_START_TIME), $dec);
}
/**
@@ -97,7 +104,7 @@ class Debug
*/
public static function getUseMem($dec = 2)
{
$size = memory_get_usage() - START_MEM;
$size = memory_get_usage() - THINK_START_MEM;
$a = ['B', 'KB', 'MB', 'GB', 'TB'];
$pos = 0;
while ($size >= 1024) {
@@ -177,4 +184,43 @@ class Debug
}
}
public static function inject(Response $response)
{
$config = Config::get('trace');
$type = isset($config['type']) ? $config['type'] : 'Html';
if (false !== $type) {
$request = Request::instance();
$accept = $request->header('accept');
$contentType = $response->getHeader('Content-Type');
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
unset($config['type']);
if (class_exists($class)) {
$trace = new $class($config);
} else {
throw new ClassNotFoundException('class not exists:' . $class, $class);
}
if ($response instanceof Redirect) {
//TODO 记录
} elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
//TODO 记录
} elseif (!empty($contentType) && strpos($contentType, 'html') === false) {
//TODO 记录
} else {
$output = $trace->output(Log::getLog());
if (is_string($output)) {
// trace调试信息注入
$content = $response->getContent();
$pos = strripos($content, '</body>');
if (false !== $pos) {
$content = substr($content, 0, $pos) . $output . substr($content, $pos);
} else {
$content = $content . $output;
}
$response->content($content);
}
}
}
}
}
+1 -1
View File
@@ -1820,7 +1820,7 @@ class Query
if (empty($options['fetch_sql']) && !empty($options['cache'])) {
// 判断查询缓存
$cache = $options['cache'];
if (true === $cache['key'] && !is_array($data)) {
if (true === $cache['key'] && !is_null($data) && !is_array($data)) {
$key = 'think:' . $options['table'] . '|' . $data;
} else {
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
+1
View File
@@ -18,6 +18,7 @@ use think\db\Builder;
*/
class Mysql extends Builder
{
protected $updateSql = 'UPDATE %TABLE% %JOIN% SET %SET% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%';
/**
* 字段和表名处理
+9 -8
View File
@@ -47,7 +47,7 @@ class Oracle extends Connection
* @param string $sql sql指令
* @param array $bind 参数绑定
* @param boolean $getLastInsID 是否获取自增ID
* @param string $sequence 序列名
* @param string $sequence 序列名
* @return integer
* @throws \Exception
* @throws \think\Exception
@@ -60,16 +60,16 @@ class Oracle extends Connection
}
// 根据参数绑定组装最终的SQL语句
$this->queryStr = $this->getBindSql($sql, $bind);
$this->queryStr = $this->getRealSql($sql, $bind);
$flag = false;
if (preg_match("/^\s*(INSERT\s+INTO)\s+(\w+)\s+/i", $sql, $match)) {
if(is_null($sequence)){
if (is_null($sequence)) {
$sequence = Config::get("db_sequence_prefix") . str_ireplace(Config::get("database.prefix"), "", $match[2]);
}
$flag = (boolean) $this->query("SELECT * FROM all_sequences WHERE sequence_name='" . strtoupper($sequence) . "'");
$flag = (boolean) $this->query("SELECT * FROM all_sequences WHERE sequence_name='" . strtoupper($sequence) . "'");
}
//释放前次的查询结果
if (!empty($this->PDOStatement)) {
$this->free();
@@ -89,7 +89,7 @@ class Oracle extends Connection
$this->lastInsID = $this->linkID->lastInsertId();
if ($getLastInsID) {
return $this->lastInsID;
}
}
}
return $this->numRows;
} catch (\PDOException $e) {
@@ -130,7 +130,7 @@ class Oracle extends Connection
/**
* 取得数据库的表信息(暂时实现取得用户表信息)
* @access public
* @param string $dbName
* @param string $dbName
* @return array
*/
public function getTables($dbName = '')
@@ -155,7 +155,8 @@ class Oracle extends Connection
return [];
}
protected function supportSavepoint(){
protected function supportSavepoint()
{
return true;
}
}
@@ -9,7 +9,7 @@
// | Author: yangweijie <yangweijiester@gmail.com>
// +----------------------------------------------------------------------
namespace think\debug\trace;
namespace think\debug;
use think\Cache;
use think\Config;
@@ -34,7 +34,7 @@ class Console
}
/**
* 日志写入接口
* 调试输出接口
* @access public
* @param array $log 日志信息
* @return bool
@@ -42,9 +42,9 @@ class Console
public function output(array $log = [])
{
// 获取基本信息
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME;
$reqs = number_format(1 / $runtime, 2);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
if (isset($_SERVER['HTTP_HOST'])) {
$uri = $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
@@ -126,12 +126,12 @@ JS;
}
break;
case '错误':
$msg = str_replace(PHP_EOL, '\n', $m);
$msg = str_replace("\n", '\n', $m);
$style = 'color:#F4006B;font-size:14px;';
$line[] = "console.error(\"%c{$msg}\", \"{$style}\");";
break;
case 'sql':
$msg = str_replace(PHP_EOL, '\n', $m);
$msg = str_replace("\n", '\n', $m);
$style = "color:#009bb4;";
$line[] = "console.log(\"%c{$msg}\", \"{$style}\");";
break;
@@ -9,7 +9,7 @@
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\debug\trace;
namespace think\debug;
use think\Cache;
use think\Config;
@@ -34,7 +34,7 @@ class Html
}
/**
* 日志写入接口
* 调试输出接口
* @access public
* @param array $log 日志信息
* @return bool
@@ -43,9 +43,9 @@ class Html
{
// 获取基本信息
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME;
$reqs = number_format(1 / $runtime, 2);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
// 页面Trace信息
if (isset($_SERVER['HTTP_HOST'])) {
@@ -9,7 +9,7 @@
// | Author: luofei614 <weibo.com/luofei614>
// +----------------------------------------------------------------------
namespace think\log\driver;
namespace think\debug;
/**
* github: https://github.com/luofei614/SocketLog
@@ -55,20 +55,20 @@ class Socket
}
/**
* 日志写入接口
* 调试输出接口
* @access public
* @param array $logs 日志信息
* @return bool
*/
public function save(array $logs = [])
public function output(array $logs = [])
{
if (!$this->check()) {
return false;
}
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_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);
$memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
$memory_str = " [内存消耗:{$memory_use}kb]";
$file_load = " [文件加载:" . count(get_included_files()) . "]";
-63
View File
@@ -1,63 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\debug;
use think\Config;
use think\exception\ClassNotFoundException;
use think\Log;
use think\Request;
use think\Response;
use think\response\Redirect;
class Trace
{
public static function inject(Response $response)
{
$config = Config::get('trace');
$type = isset($config['type']) ? $config['type'] : 'Html';
if ($type !== false) {
$request = Request::instance();
$accept = $request->header('accept');
$contentType = $response->getHeader('Content-Type');
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\trace\\' . ucwords($type);
unset($config['type']);
if(class_exists($class)) {
$trace = new $class($config);
} else {
throw new ClassNotFoundException('class not exists:' . $class, $class);
}
if ($response instanceof Redirect) {
//TODO 记录
} elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
//TODO 记录
} elseif (!empty($contentType) && strpos($contentType, 'html') === false) {
//TODO 记录
} else {
$output = $trace->output(Log::getLog());
$content = $response->getContent();
$pos = strripos($content, '</body>');
if (false !== $pos) {
$content = substr($content, 0, $pos) . $output . substr($content, $pos);
} else {
$content = $content . $output;
}
$response->content($content);
}
}
}
}
+2 -2
View File
@@ -54,10 +54,10 @@ class File
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_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);
$memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
$memory_str = " [内存消耗:{$memory_use}kb]";
$file_load = " [文件加载:" . count(get_included_files()) . "]";
+2 -2
View File
@@ -33,10 +33,10 @@ class Sae
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_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);
$memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
$memory_str = " [内存消耗:{$memory_use}kb]";
$file_load = " [文件加载:" . count(get_included_files()) . "]";