Poll: Would you find a globally enabled profiler helpful?
You do not have permission to vote in this poll.
Yes, I would like to see a global switch for enabling the profiler
8 57.14%
No, it is fine as it is.
6 42.86%
Total 14 vote(s) 100%
* You voted for this item. [Show Results]

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enable profiler globally

Just a quick one, I would like to be able to switch the profiler on and off globally.


Best wishes,


I'm not sure I understand what you're looking for. As far as I know, the code you included already works fine. In fact, I have a method in my base controller which does this.

PHP Code:
   protected function showProfiler($frontEnd true)
       // $this->input->is_cli_request() is deprecated in CI 3.0, but the replacement
       // common is_cli() function is not available in CI 2.2.
       $isCliRequest substr(CI_VERSION01) == '2' $this->input->is_cli_request() : is_cli();
       if (! $isCliRequest
&& ! $this->input->is_ajax_request()
       ) {
           if ($frontEnd == false
|| $this->settings_lib->item('site.show_front_profiler')
           ) {

Then I call the method in my base controller's constructor based on the ENVIRONMENT. My admin controller passes false to the method to bypass the check against the site.show_front_profiler setting.

Obviously, some of this code isn't going to work in a base CI installation without the appropriate libraries, but the basic idea should still work.

He wants the option to enable it in autoload.php config.

It takes a few lines of code to create a MY_Controller that does what the OP is asking for.

Sure, so does every other thing in autoload config

(04-29-2015, 11:23 AM)gadelat Wrote: He wants the option to enable it in autoload.php config.

Yes, that is exactly what I meant. Perhaps not in the autoload file specifically but certainly somewhere relevant.

Something like

| Profiler Global SETTING
| This item determines if the profiler should be enabled globally on all pages.
$config['enable_profiler_globally'] = FALSE;

OR even with the default display settings options as well:

$global_default_sections = array(
  'benchmarks'  => TRUE,
  'config'  => TRUE,
  'controller_info'  => TRUE,
  'get'  => TRUE,
  'http_headers'  => TRUE,
  'memory_usage'  => TRUE,
  'post'  => TRUE,
  'queries'  => TRUE,
  'uri_string'  => TRUE,
  'session_data'  => TRUE,
  'query_toggle_count'  => 25,

Now that would be really, really helpful IMHO :-)

I have just realized that this might be more complicated than I imagine because it would have to override the individual controller settings, but if it was available globally I don't imagine people would bother with it in individual controllers. So I suppose you would need three options, turn on for all pages, turn off for all pages, or leave it up to individual controllers to turn on if set. Then, when a site is ready for going live you could globally switch off the profiler so any controllers still set to show accidentally in individual controllers are overridden. During development you could set the global profiler on so when needed you can see it on all pages. Or you can just use it on a per controller basis as is the case now.

I think people would like that, I certainly would, so just thought I would mention it as an idea.

Best wishes,


If it is introduced, maybe this global option should be not enforced in the same way for AJAX requests that output in non-HTML formats. For example, if an AJAX request returns in JSON format, the additional output from the profiler will damage the result, the client will be not able to parse it.

I have never tried the profiler on CLI, in this case there should be a special profiler output, pure text.

Related also with "REST support" http://forum.codeigniter.com/thread-61374.html
REST response could be in different formats, the profiler output should not damage them.

This is how I do it with a profiler.php config file.

Top of index.php or some place else.

PHP Code:
 * ------------------------------------------------------------------------
 * Profiler - true / false set to true to enable.
 * ------------------------------------------------------------------------

PHP Code:
     * --------------------------------------------------------------------
     * __construct()
     * Class    Constuctor PHP 5+
     * @access      public
     * @internal    param $string
     * @return      \Base_Controller
public function __construct()

// use profiler
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.