Change Codeigniter profiler to send output to db instead of showing on page

I would like to use the CI profiler as a tool to audit the application. However, obviously, in this case I do not want the output to be displayed on the page, but rather written to db.

I thought I could connect to the profiler, capture the relevant details (query, uri_string, etc.) and send them to the table in db.

I could extend the profiler class to send data to db, but this does not exclude the output to the screen. From time to time, I would also like to use a profiler, so re-writing the output class is undesirable.

Any ideas appreciated.


What I have finished is creating a library and copylasagna Profiler.php into it to change as needed.

+4
source share
2 answers

Try it. Add MY_Profiler.php to the library / directory (I assume you are in the 2.0+ branch, and if not, do you know the lemma):

<?php class MY_Profiler extends CI_Profiler { public function run() { $output = parent::run(); // log output here, and optionally return it if you do want it to display } } 

EDIT: And to automatically enable the profiler for each controller (add to core / MY_Controller.php):

 <?php class MY_Controller extends CI_Controller { public function __construct() { parent::__construct(); $this->output->enable_profiler(TRUE); } } // but each controller will have to extend MY_Controller, not CI_Controller... class Somecontroller extends MY_Controller { //... } 
+7
source

You can hack core/Output to save the output of the Profiler class to DB, or display it on the screen, or both. Just add another switch, similar to $this->enable_profiler ;

You can also take a look at xdebug . This allows you to profile applications, write profiles to disk, and analyze them later.

-1
source

Source: https://habr.com/ru/post/1381316/


All Articles