CodeIgniter Forums
Enable profiler globally - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Enable profiler globally (/showthread.php?tid=61590)

Pages: 1 2


RE: Enable profiler globally - John_Betong - 04-29-2015

Try adding the following in your own ./config/config_personal.php
PHP Code:
<?php # config_personal.php

defined ?: define('LOCALHOST, 'localhost'=== $_SERVER['SERVER_NAME']);

if( LOCALHOST):
    define('
GOOGLE_ON', FALSE);
    $_SESSION['
jjj'] = array
    (
    '
angular'         =>  FALSE,   
    '
error_reporting' => -1,        #-1==LOCAL 
    '
display_errors'  =>  1,        # 1==LOCAL
    '
threshold'       =>  1,        # 1..4 agressive
    '
compress_result' =>  FALSE,    # 
    '
profiler'        =>  TRUE,     # DOES NOT ACCEPT 0 AS FALSE ?????
    '
MD5'             =>  1,        # 1 == show cached filename
    '
cache_minutes'   =>  0,        # minutes
    '
cache_path'      =>  CACHEPATH,# define('CACHEPATH', APPPATH  .'cache/current/');
    );
else: # Must be ONLINE
  define('
GOOGLE_ON', FALSE);
  $_SESSION['
jjj'] = array
  (
  '
angular'         =>  FALSE,   
  '
error_reporting' =>  -1,
  '
display_errors'  =>  FALSE,     # FALSE ONLINE
  '
threshold'       =>  1,         # 1 ONLINE - 1..4 agressive
  '
compress_result' =>  FALSE,     # Bl@@dy DISQUS DOES NOT WORK if COMPRESSED
  '
profiler'        =>  FALSE,     # DOES NOT ACCEPT 0 AS FALSE ?????
  '
cache_minutes'   =>  0,         # 1,440 = minutes per day
  '
cache_path'      =>  CACHEPATH, # define('CACHEPATH', APPPATH  .'cache/current/');
  );
endif; 
ini_set('
error_log', APPPATH .'php_error.php');
error_reporting( $_SESSION['
jjj']['error_reporting'] );
ini_set('
display_errors', $_SESSION['jjj']['display_errors'] ); 
and I also have a common MY_Library:
PHP Code:
//==================================================

class MY_Library extends CI_Controller 
{

function 
j_view(& $data=array(), $getLatestAndThumbs=TRUE)
{
 
 $this->output->enable_profiler$_SESSION['jjj']['profiler'] );
 
 // lots of other stuff

 
 $this->load->view$data['page_new'], $dataFALSE); # FALSE == ON SCREEN display
}//endfunc

}/// endclass 
This has worked for many old CI_VERSIONS without any problems.


RE: Enable profiler globally - PaulD - 04-30-2015

(04-29-2015, 03:32 PM)ivantcholakov Wrote: 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.

Yes that is true, and a good point. In fact also true of normal AJAX requests too. And how would that be identified? From the header? That is probelmatic in itself I suspect.

From above
(04-29-2015, 06:07 PM)InsiteFX Wrote: This is how I do it with a profiler.php config file.

That is a really neat and clever suggestion. Then I can include or not include in controllers I use for ajax and other things where the profiler would not be required. I really like this approach. Simple, clear and effective. Thank you. At the moment I just include the profiler line in all my controllers but commented out and I uncomment when I need it. However going to all the individual controllers (especially in a complicated routing site) is a pain. Your approach will work superbly for me, thank you again.

Anyway, given all the points raised in earlier posts, perhaps enabling the profiler globally just has too many complications and inherent problems. I would still like to have it as a config or autoload global variable, but I can see now why maybe the CI developers would prefer not to do it.

The debugging help provided by the profiler is just so useful and so powerful that I thought it would be handy to turn it on for all pages when needed and off for all pages when a site goes live globally.

Thanks for all the replies though.

Best wishes,

Paul


RE: Enable profiler globally - PaulD - 04-30-2015

(04-29-2015, 07:22 PM)John_Betong Wrote: Try adding the following in your own ./config/config_personal.php
...

That seems an interesting approach too, but I would have to explore it in a bit more detail. But thanks for posting it, I will certainly take a more detailed look at it when I have time to try it out.

Thank you for the suggestion and code though,

Paul.


RE: Enable profiler globally - ivantcholakov - 04-30-2015

I like the idea, although I've pointed out at some practical difficulties. Maybe they are solvable.


RE: Enable profiler globally - InsiteFX - 05-01-2015

profiler.php - Create this file in application/config

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/*
| -------------------------------------------------------------------------
| Profiler Sections
| -------------------------------------------------------------------------
| This file lets you determine whether or not various sections of Profiler
| data are displayed when the Profiler is enabled.
| Please see the user guide for info:
|
| http://codeigniter.com/user_guide/general/profiling.html
|
*/

$config['benchmarks'] = TRUE// Elapsed time of Benchmark points and total execution time.
$config['config'] = TRUE// CodeIgniter Config variables.
$config['controller_info'] = TRUE// The Controller class and method requested.
$config['get'] = TRUE// Any GET data passed in the request.
$config['http_headers'] = TRUE// The HTTP headers for the current request.
$config['memory_usage'] = TRUE// Amount of memory consumed by the current request, in bytes.
$config['post'] = TRUE// Any POST data passed in the request.
$config['queries'] = TRUE// Listing of all database queries executed, including execution time.
$config['uri_string'] = TRUE// The URI of the current request.
$config['session_data'] = TRUE// Data stored in the current session.
$config['query_toggle_count'] = 25// The number of queries after which the query block will default to hidden.

/**
 * ------------------------------------------------------------------------
 * Filename: profiler.php
 * Location: ./application/config/profiler.php
 * ------------------------------------------------------------------------
 */ 
config.php - Add to the top of file
PHP Code:
/*
|--------------------------------------------------------------------------
| Use CodeIgniter Profiler
|--------------------------------------------------------------------------
|
/ TRUE / FALSE
|
*/
$config['profiler'] = FALSE

MY_Controller
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * ------------------------------------------------------------------------
 * Editor  : phpDesigner 8.1.2
 * Date    : 10/17/2013
 * Time    : 9:07:10 AM
 * Authors : Raymond L King Sr.
 * ------------------------------------------------------------------------
 *
 * Class    MY_Controller
 *
 * ------------------------------------------------------------------------
 * To change this template use File | Settings | File Templates.
 * ------------------------------------------------------------------------
 */

class Base_Controller extends CI_Controller {

    
/**
     * --------------------------------------------------------------------
     * Class variables - public, private, protected and static.
     * --------------------------------------------------------------------
     */


     // --------------------------------------------------------------------

    /**
     *  __construct
     *
     * Class Constructor    PHP 5+
     *
     * @access    public
     * @return    void
     */
    
public function __construct()
    {
        
parent::__construct();

        
// check to see if we want to use the CI profiler.
        
$this->output->enable_profiler($this->config->item('profiler'));

    }

Quick and simple


RE: Enable profiler globally - RWCH - 05-01-2015

I have used a similar approach as InsiteFX. It's simple. Anybody can use it this way, so no need for 'extra switches'.

Configuration is simply done in your configuration file ... also for enabling/disabling a profiler.