CodeIgniter Profiler Extended

CodeIgniter includes a built in Profiler class that really helps debugging your php applications in real-time. I highly recommend using it if you aren’t already. It’s really simple to enable, just add this one line to your php code and refresh your application.

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

The profiler data will be displayed in the footer of your php application.

While the default CodeIgniter Profiler class is good, I’ve been using an extended version that displays a lot more debugging information and uses a profiler.php config file for easy of use.

Here’s how to use it in your php application.

Step 1: Create a profiler.php config file and include the following config options.

$config['enable_profiler'] 			= 1;
$config['show_uri_string'] 			= 1;
$config['show_controller_info']		= 1;
$config['show_memory_usage'] 		= 1;
$config['show_benchmarks'] 			= 1;
$config['show_cookies'] 			= 1;
$config['show_get_vars'] 			= 1;
$config['show_post_vars'] 			= 1;
$config['show_uri_vars'] 			= 1;
$config['show_tpl_vars'] 			= 1;
$config['show_session_userdata']	= 1;
$config['show_db_multi_queries'] 	= 0; // Only enable if you need to show more than one database in the profiler

Step 2. Add the following lines to the constructor of your current controller or in the constructor of a parent controller.

// Load the profile.php config file if it exists
$this->config->load('profiler', false, true);
if ($this->config->config['enable_profiler']) {
	$this->output->enable_profiler(TRUE);
}

Step 3. Upload the custom My_Profiler.php file to your libraries directory.

And here’s what you new profiler will look like:

CodeIgniter Profiler Extended

Be sure to change the “subclass_prefix” to match what you have in your config.php file.

If you found this article useful, please share your comments below.

Tags: , , ,