本文整理匯總了PHP中think\Debug::getFile方法的典型用法代碼示例。如果您正苦於以下問題:PHP Debug::getFile方法的具體用法?PHP Debug::getFile怎麽用?PHP Debug::getFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類think\Debug
的用法示例。
在下文中一共展示了Debug::getFile方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: output
/**
* 調試輸出接口
* @access public
* @param Response $response Response對象
* @param array $log 日誌信息
* @return bool
*/
public function output(Response $response, array $log = [])
{
$request = Request::instance();
$contentType = $response->getHeader('Content-Type');
$accept = $request->header('accept');
if (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
return false;
} elseif (!empty($contentType) && strpos($contentType, 'html') === false) {
return false;
}
// 獲取基本信息
$runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME;
$reqs = number_format(1 / $runtime, 2);
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
// 頁麵Trace信息
if (isset($_SERVER['HTTP_HOST'])) {
$uri = $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} else {
$uri = 'cmd:' . implode(' ', $_SERVER['argv']);
}
$base = ['請求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $uri, '運行時間' => number_format($runtime, 6) . 's [ 吞吐率:' . $reqs . 'req/s ] 內存消耗:' . $mem . 'kb 文件加載:' . count(get_included_files()), '查詢信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ', '緩存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes', '配置加載' => count(Config::get())];
if (session_id()) {
$base['會話信息'] = 'SESSION_ID=' . session_id();
}
$info = Debug::getFile(true);
// 頁麵Trace信息
$trace = [];
foreach ($this->config['trace_tabs'] as $name => $title) {
$name = strtolower($name);
switch ($name) {
case 'base':
// 基本信息
$trace[$title] = $base;
break;
case 'file':
// 文件信息
$trace[$title] = $info;
break;
default:
// 調試信息
if (strpos($name, '|')) {
// 多組信息
$names = explode('|', $name);
$result = [];
foreach ($names as $name) {
$result = array_merge($result, isset($log[$name]) ? $log[$name] : []);
}
$trace[$title] = $result;
} else {
$trace[$title] = isset($log[$name]) ? $log[$name] : '';
}
}
}
// 調用Trace頁麵模板
ob_start();
include $this->config['trace_file'];
return ob_get_clean();
}
示例2: save
/**
* 日誌寫入接口
* @access public
* @param array $log 日誌信息
* @return bool
*/
public function save(array $log = [])
{
if (IS_AJAX || IS_CLI || IS_API || 'html' != Config::get('default_return_type')) {
// ajax cli api方式下不輸出
return false;
}
// 獲取基本信息
$runtime = microtime(true) - START_TIME;
$reqs = number_format(1 / $runtime, 2);
$runtime = number_format($runtime, 6);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
// 頁麵Trace信息
$base = ['請求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '運行時間' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 內存消耗:{$mem}kb 文件加載:" . count(get_included_files()), '查詢信息' => \think\Db::$queryTimes . ' queries ' . \think\Db::$executeTimes . ' writes ', '緩存信息' => \think\Cache::$readTimes . ' reads,' . \think\Cache::$writeTimes . ' writes', '配置加載' => count(Config::get())];
if (session_id()) {
$base['會話信息'] = 'SESSION_ID=' . session_id();
}
$info = Debug::getFile(true);
// 獲取調試日誌
$debug = [];
foreach ($log as $line) {
$debug[$line['type']][] = $line['msg'];
}
// 頁麵Trace信息
$trace = [];
foreach ($this->config['trace_tabs'] as $name => $title) {
$name = strtolower($name);
switch ($name) {
case 'base':
// 基本信息
$trace[$title] = $base;
break;
case 'file':
// 文件信息
$trace[$title] = $info;
break;
default:
// 調試信息
if (strpos($name, '|')) {
// 多組信息
$names = explode('|', $name);
$result = [];
foreach ($names as $name) {
$result = array_merge($result, isset($debug[$name]) ? $debug[$name] : []);
}
$trace[$title] = $result;
} else {
$trace[$title] = isset($debug[$name]) ? $debug[$name] : '';
}
}
}
// 調用Trace頁麵模板
ob_start();
include $this->config['trace_file'];
echo ob_get_clean();
return true;
}
示例3: save
/**
* 日誌寫入接口
* @access public
* @param array $log 日誌信息
* @return void
*/
public function save($log = [])
{
// 獲取基本信息
$current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$runtime = number_format(microtime(true) - START_TIME, 6);
$reqs = number_format(1 / $runtime, 2);
// 頁麵Trace信息
$base = ['請求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $current_uri, '運行時間' => "{$runtime}s [ 吞吐率:{$reqs}req/s ]", '內存消耗' => number_format((memory_get_usage() - START_MEM) / 1024, 2) . 'kb', '查詢信息' => \think\Db::$queryTimes . ' queries ' . \think\Db::$executeTimes . ' writes ', '緩存信息' => \think\Cache::$readTimes . ' reads,' . \think\Cache::$writeTimes . ' writes', '文件加載' => count(get_included_files()), '配置加載' => count(\think\Config::get()), '會話信息' => 'SESSION_ID=' . session_id()];
$info = \think\Debug::getFile(true);
// 獲取調試日誌
$debug = [];
foreach ($log as $line) {
$debug[$line['type']][] = $line['msg'];
}
// 頁麵Trace信息
$trace = [];
foreach ($this->tabs as $name => $title) {
$name = strtolower($name);
switch ($name) {
case 'base':
// 基本信息
$trace[$title] = $base;
break;
case 'file':
// 文件信息
$trace[$title] = $info;
break;
default:
// 調試信息
if (strpos($name, '|')) {
// 多組信息
$names = explode('|', $name);
$result = [];
foreach ($names as $name) {
$result = array_merge($result, isset($debug[$name]) ? $debug[$name] : []);
}
$trace[$title] = $result;
} else {
$trace[$title] = isset($debug[$name]) ? $debug[$name] : '';
}
}
}
// 調用Trace頁麵模板
ob_start();
include $this->config['trace_file'];
echo ob_get_clean();
}
示例4: testGetFile
/**
* @covers think\Debug::getFile
* @todo Implement testGetFile().
*/
public function testGetFile()
{
$count = \think\Debug::getFile();
$this->assertEquals(count(get_included_files()), $count);
$info = \think\Debug::getFile(true);
$this->assertEquals(count(get_included_files()), count($info));
$this->assertContains("KB", $info[0]);
}