
- CodeIgniter 教程
- CodeIgniter - 首頁
- CodeIgniter - 概述
- CodeIgniter - 安裝 CodeIgniter
- CodeIgniter - 應用架構
- CodeIgniter - MVC 框架
- CodeIgniter - 基本概念
- CodeIgniter - 配置
- CodeIgniter - 資料庫操作
- CodeIgniter - 庫
- CodeIgniter - 錯誤處理
- CodeIgniter - 檔案上傳
- CodeIgniter - 傳送郵件
- CodeIgniter - 表單驗證
- CodeIgniter - 會話管理
- CodeIgniter - Flash 資料
- CodeIgniter - Temp 資料
- CodeIgniter - Cookie 管理
- CodeIgniter - 常用函式
- CodeIgniter - 頁面快取
- CodeIgniter - 頁面重定向
- CodeIgniter - 應用效能分析
- CodeIgniter - 基準測試
- CodeIgniter - 新增 JS 和 CSS
- CodeIgniter - 國際化
- CodeIgniter - 安全性
- CodeIgniter 有用資源
- CodeIgniter - 快速指南
- CodeIgniter - 有用資源
- CodeIgniter - 討論
CodeIgniter - 應用效能分析
在構建web應用程式時,我們非常關注網站的效能,例如控制器執行需要多長時間以及使用了多少記憶體。不僅是效能,在開發某些應用程式時,我們還需要檢視POST資料、資料庫查詢資料、會話資料等資料的洞察資訊以進行除錯。CodeIgniter 透過對應用程式進行效能分析使這項工作變得更容易。
啟用效能分析
要啟用應用程式的效能分析,只需在控制器的任何方法中執行以下命令。
$this->output->enable_profiler(TRUE);
啟用後,可以在頁面底部看到效能分析報告。
停用效能分析
要停用應用程式的效能分析,只需在控制器的任何方法中執行以下命令。
$this->output->enable_profiler(FALSE);
啟用/停用效能分析器部分
效能分析可以基於部分進行。您可以透過設定布林值 TRUE 或 FALSE 來啟用或停用某一部分的效能分析。如果要在應用程式上設定效能分析,則可以在位於 **application/config/profiler.php** 檔案中進行。
例如,以下命令將為整個應用程式啟用查詢效能分析。
$config['queries'] = TRUE;
在下表中,鍵是引數,可以在 config 陣列中設定以啟用或停用特定配置檔案。
鍵 | 描述 | 預設值 |
---|---|---|
benchmarks |
基準點經過的時間和總執行時間 | TRUE |
config |
CodeIgniter 配置變數 | TRUE |
controller_info |
請求的控制器類和方法 | TRUE |
get |
請求中傳遞的任何 GET 資料 | TRUE |
http_headers |
當前請求的 HTTP 頭 | TRUE |
memory_usage |
當前請求消耗的記憶體量(以位元組為單位) | TRUE |
post |
請求中傳遞的任何 POST 資料 | TRUE |
queries |
所有執行的資料庫查詢列表,包括執行時間 | TRUE |
uri_string |
當前請求的 URI | TRUE |
session_data |
當前會話中儲存的資料 | TRUE |
query_toggle_count |
查詢數達到多少之後,查詢塊將預設為隱藏。 | 25 |
可以透過在控制器中使用 **set_profiler_sections()** 函式覆蓋 **application/config/profiler.php** 檔案中設定的效能分析器。如下所示。
$sections = array( 'config' => TRUE, 'queries' => TRUE ); $this->output->set_profiler_sections($sections);
廣告