CodeIgniter comes with a great profiler already, so why a replacement? Let's face it, sometimes it just gets in the way. Or it kills your AJAX request dead. And it's kinda ugly (sorry, CI). And there's more that it could be doing.
What's New?
Forensics adds a few things to the stock Profiler that should make your life as a developer a bit easier. At least when it comes to debugging.
- The Profiler output is now completely skinnable. If you've read the comments in the Profiler class before, this is something that the EllisLab devs have said for a while it would be nice to do. Congrats. It's done.
- The output now also includes a list of all files that your CodeIgniter app includes, as well as their location (relative to your FCPATH).
- Output also has the ability to log items and track memory in your project via a new console class.
- Any variables sent to the view are shown in the bar.
The default look, and some of the additional functionality, was heavily inspired by ParticleTree's PHP Quick Profiler.
Installing
Forensics is intended to be used as a Spark. However, it is best installed using Composer.
Create a composer.json
file in your application's root (alongside the application and spark folders). Add the following text in the new file:
{
"require": {
"lonnieezell/codeigniter-forensics": "dev-master"
}
}
In your application, you will first need to load the newly installed spark, then enable the profiler like normal.
$this->load->spark('codeigniter-forensics');
$this->output->enable_profiler(true);
Forensics Logging
In addition to the normal information that CI's Profiler provides, you now have two new logging commands at your disposal that work with the Forensics Profiler:
Console::log($data)
This function accepts any data type and simply creates a pretty, readable output of the variable, using print_r(). Very handy for logging where you are in the script execution, or outputting the contents of an array, or stdObject to your new 'console'.
Console::log_memory($variable, $name)
The log_memory function has two uses.
1) When no parameters are passed in, it will record the current memory usage of your script. This is perfect for watching a loop and checking for memory leaks.
2) If you pass in the $variable and $name parameters, will output the amount of memory that variable is using to the console.
In order to use either of these functions, you must be sure to load the Console library before you use it.
Other Tips
You can change the location of the profiler bar by changing the $bar_location
variable at the top of the profiler_template view to one of the following locations:
- top-right
- top-left
- bottom-left
- bottom-right
- top
- bottom
What About the Future?
This profiler bar has been around for a couple of years now and not much has happened to it. It was incorporated into one of my other projects, Bonfire, but not much else has happened. Heck, someone else even had to be the one to make a Spark out of it. Bad me.
No more.
The profiler bar is just the start of what I'm kicking around. Forensics is all about finding out what's going on in your application as you're building it. I plan on expanding Forensics to provide even more goodies, all sharing a single "theme" that you can customize to your business' branding. Tools like better var_dumps, better error and exception handling. It's going to require some digging, but I'm also thinking we might be able to integrate with XDebug, if it's installed on your system. That's one a long shot, though.
If you have any ideas or want to make some contributions, please do!