Welcome Guest, Not a member yet? Register   Sign In
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
57.14%
8 57.14%
No, it is fine as it is.
42.86%
6 42.86%
Total 14 vote(s) 100%
* You voted for this item. [Show Results]

Enable profiler globally
#11

(This post was last modified: 04-29-2015, 07:27 PM by John_Betong. Edit Reason: spelling: not my fortay )

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.
Reply
#12

(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
Reply
#13

(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.
Reply
#14

(This post was last modified: 04-30-2015, 12:05 PM by ivantcholakov. Edit Reason: Grammar )

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

(This post was last modified: 05-01-2015, 01:19 AM by InsiteFX.)

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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#16

(This post was last modified: 05-01-2015, 06:09 AM by RWCH.)

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB