In this tutorial we will learn about CodeIgniter Application Profiling. When building a web application, we are very concerned about the website’s performance in terms of how long the controller has been running and how much memory is used. Not only performance, but also data insights such as POST data, database query data, session data, etc. Developing some application for debugging purposes. CodeIgniter facilitated this task by profiling an application.

Enable CodeIgniter Profiling

To allow profiling of your application, simply execute the command in any of your controller’s methods below.

$this->output->enable_profiler(TRUE);

The profile report can be viewed at the bottom of the page after it has been enabled.

Disable CodeIgniter Profiling

To deactivate your application profiling, simply execute the command below in any of your controller’s methods.

$this->output->enable_profiler(FALSE);

Enable / Disable Profiler

Profiling can be done on the basis of section. You can activate or deactivate section profiling by setting a TRUE or FALSE Boolean value. If you want to set profiling to the application, you can do it in the application/config/profiler.php file.

The following command, for example, allows profiling of queries for the entire application.

$config['queries'] = TRUE;

The key in the following table is the parameter that can be set to activate or deactivate a particular profile in the config array.

Key Description Default
benchmarks Benchmark time and total execution time have elapsed. TRUE
config CodeIgniter Config variables TRUE
controller_info The type and method of controller requested TRUE
get Any GET data passed in the request TRUE
http_headers The HTTP headers for the current request TRUE
memory_usage Amount of memory consumed in bytes by the current request. TRUE
post Any POST data passed in the request TRUE
queries Listing all executed database requests, including execution time. TRUE
uri_string The URI of the current request TRUE
session_data Data stored in the current session TRUE
query_toggle_count The number of queries after which the query block is hidden by default. 25

The profile set in the application/config/profiler.php file can be overridden with the set_profiler_sections() function in the controllers shown below.

$sections = array( 
   'config'  => TRUE, 
   'queries' => TRUE 
); 
 
$this->output->set_profiler_sections($sections);