![]() |
[CODE] Easy On/Off Debugging and Profiling - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: [CODE] Easy On/Off Debugging and Profiling (/showthread.php?tid=33307) |
[CODE] Easy On/Off Debugging and Profiling - El Forum - 08-21-2010 [eluser]pbarney[/eluser] If you're like me, you're often putting var_dump or $this->output->enable_profiler() in your source code while you're debugging it. I got tired of commenting and un-commenting these lines, so I came up with an easier system. Some of you may be familiar with the PHP XDEBUG extension. Whether or not you use it, the Firefox add-on Easy XDebug (any also, I believe, the Chrome add-on Xdebug Helper) provides a really nice way to turn our debugging messages on and off. For all else they may do, the extensions do one interesting thing in particular: set or delete two special cookies (XDEBUG_SESSION and XDEBUG_PROFILE) that we can use to let our app know if we're in "debugging mode" or "profile mode". So here's what I came up with: In config.php, add the following block: Code: /* Now you can do handy things like: Code: if (DEBUG) echo "<pre>" . print_r($this->session->userdata,true) . "</pre>"; Once you've installed the browser add-on, just click either of the tiny green buttons in the status bar to enable or disable either debugging or profiling. (Note: If you're behind a proxy, you might also want to check $_SERVER['HTTP_X_FORWARDED_FOR'] when checking for the trusted host ip, which I leave as an exercise for the reader.) Thoughts? |