Profiler serves to display some of the information needed in developing and debugging applications.
With profilers we can see:
- The time needed to execute the controller
- What queries are executed
- Query execution speed
- Data sent
- etc.
This information is very useful when we build applications with CodeIgniter.
Enable the CodeIgniter Profiler
How to activate Profiler on CodeIgniter is very easy, just by running this function in the controller .
$this->output->enable_profiler(TRUE);
Then we will get information like the following:
Then, for the Profiler to be active in each method or function, put the code in the constructor:
function __construct(){
parent::construct();
// untuk debugging
$this->output->enable_profiler(TRUE);
}
Disable the CodeIgniter Profiler
How to disable it, we can delete the function or change its parameters to false.
$this->output->enable_profiler(FALSE);
But later the problem is, when we want to deploy to the server ...
... we have to change each profiler function to
FALSE
.
This is not effective.
Then what is the solution?
The solution is we can use variables
ENVIRONTMENT
.$this->output->enable_profiler(ENVIRONMENT == 'development');
So if the value of the variable
ENVIRONTMENT
is development
(localhost), then it will produce a value TRUE
.
But if the value of a variable
ENVIRONTMENT
is production
, it will produce a value FALSE
.
We can create variables
ENVIRONTMENT
inside index.php
:switch($_SERVER["HTTP_HOST"]){
case "localhost":
define('ENVIRONMENT', 'development');
break;
default:
define('ENVIRONMENT', 'production');
break;
}
Reference: https://www.petanikode.com/codeigniter-profiler/
0 Komentar untuk "How to Activate the CodeIgniter Profiler"
Silahkan berkomentar sesuai artikel