Skip to content

ansborisov/prophiler

 
 

Repository files navigation

#Prophiler - A Phalcon Profiler & Dev Toolbar

Scrutinizer Code Quality Code Coverage Build Status

Demo

Here you can see the toolbar in action: http://prophiler.fabfuel.de/

Timeline Preview

Installation

You can use composer to install the Prophiler. Just add it as dependency:

"require": {
   	"fabfuel/prophiler": "~1.0",
}

Setup

Setting up the Prophiler and the developer toolbar can be done by these simple steps. It could all be done in your front controller (e.g. public/index.php)

#####1. Initialize the Profiler (as soon as possible) Generally it makes sense to initialize the profiler as soon as possible, to measure as much execution time as you can. You should initialize the profiler in your frontcontroller or a separat bootstrap file right after requiring the Composer autoloader.

$profiler = new \Fabfuel\Prophiler\Profiler();

#####2. Add the profiler to the dependency injection container Add the profiler instance to the DI container, that other plugins and adapters can use it accros the application. This should be done in or after your general DI setup.

$di->setShared('profiler', $profiler);

#####3. Initialize the plugin manager The plugin manager registers all included framework plugins automatically and attaches them to the events manager.

$pluginManager = new \Fabfuel\Prophiler\Plugin\Manager\Phalcon($profiler);
$pluginManager->register();

#####4. Initialize and register the Toolbar

To visualize the profiling results, you have to initialize and render the Prophiler Toolbar. This component will take care for rendering all results of the Profiler benchmarks and other data collectors. Put that at the end of the frontcontroller.

You can also add other data collectors to the Toolbar, to show e.g. request data like in this example.

$toolbar = new \Fabfuel\Prophiler\Toolbar($profiler);
$toolbar->addDataCollector(new \Fabfuel\Prophiler\DataCollector\Request());
echo $toolbar->render();

You can also easily create you own data collectors, by implementing the DataCollectorInterface and adding an instance to the Toolbar at this point.

...
$toolbar->addDataCollector(new \My\Custom\DataCollector());
...

Tips

To render the toolbar as very last action, you can also register it as shutdown function:

register_shutdown_function([$toolbar, 'render']);

To record session writing, you can commit or write & close the session before rendering the toolbar

session_commit();

session_write_close() // same behavior

About

Prophiler - Phalcon Developer Toolbar

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 86.3%
  • HTML 7.7%
  • CSS 4.9%
  • Other 1.1%