2017 © Pedro Peláez
 

library prophiler

PHP Profiler & Developer Toolbar built for Phalcon

image

fabfuel/prophiler

PHP Profiler & Developer Toolbar built for Phalcon

  • Saturday, September 16, 2017
  • by fabfuel
  • Repository
  • 46 Watchers
  • 434 Stars
  • 106,273 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 46 Forks
  • 16 Open issues
  • 14 Versions
  • 7 % Grown

The README.md

Prophiler - A PHP Profiler & Developer Toolbar built for Phalcon

Scrutinizer Code Quality Code Coverage Build Status License Latest Stable Version, (*1)

Demo

The demo website has been moved to a separate repository: https://github.com/fabfuel/prophiler-demo, (*2)

Here you can see the toolbar in action: http://prophiler.fabfuel.de/demo.php, (*3)

Timeline Preview, (*4)

Installation

You can use composer to install the Prophiler. Just add it as dependency:, (*5)

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

Setup (general)

Setting up the Prophiler and the developer toolbar can be done via the following simple steps. It could all be done in your front-controller (e.g. public/index.php in Phalcon), (*6)

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 front-controller or the bootstrap file right after requiring the Composer autoloader., (*7)

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

2. Initialize and register the Toolbar

To visualize the profiling results, you have to initialize and render the Prophiler Toolbar. This component takes care for rendering all results of the profiler benchmarks and other data collectors. Put that at the end of the front-controller., (*8)

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

$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., (*10)

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

Additional setup for Phalcon applications

1. Add the profiler to the dependency injection container

Add the profiler instance to the DI container, that other plugins and adapters can use it across the application. This should be done in or after your general DI setup., (*11)

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

2. Initialize the plugin manager

The plugin manager registers all included Phalcon plugins automatically and attaches them to the events manager. To make the plugins work properly, make sure that the default events manager is attached to your Dispatcher, View and Connection services., (*12)

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

Custom Benchmarks

You can easily add custom benchmarks to your code:, (*13)

$benchmark = $profiler->start('\My\Class::doSomething', ['additional' => 'information'], 'My Component');
...
$profiler->stop($benchmark);

Or stop without passing the benchmark

In some scenarios (e.g. custom adapters) it might be hard to pass the received benchmark to the stop() method. Alternatively you can simply omit the $benchmark parameter. If that is the case, the profiler simply stops the last started benchmark, but it is not possible to run overlapping benchmarks., (*14)

$profiler->start('\My\Class::doSomeOtherThing', ['additional' => 'information'], 'My Component');
...
$profiler->stop();

Aggregations

Prophiler now features benchmark aggregations. These give you a lot more insights and are extremely useful to: - quickly see the total number of recurring executions (e.g. database or cache queries) - analyze minimum, maximum and average execution times of recurring executions - easily see (e.g. accidentally) recurring executions of the same database query - get a warning, if the total number of executions exceeds a custom threshold - get a warning, if the maximum execution time exceeds a custom threshold, (*15)

Setup

Prophiler comes with some aggregators, but you can easily create your own. To Set up an aggregator, all you need to do is to register the aggregator at the profiler instance:, (*16)

$profiler->addAggregator(new \Fabfuel\Prophiler\Aggregator\Database\QueryAggregator());
$profiler->addAggregator(new \Fabfuel\Prophiler\Aggregator\Cache\CacheAggregator());

That's it. You immediately see all database and cache queries, grouped by command/query, including the total number of executions, the total duration of all executions as well as the minimum, maximum and average execution time., (*17)

Logging

You can use Prophiler to log events and other data and view it in the timeline and in the separate "Logs" tab. If you already have a logging infrastructure, you can add the PSR-3 compliant Logger adapter to it. Otherwise you can also just instantiate and use it directly:, (*18)

$logger = new \Fabfuel\Prophiler\Adapter\Psr\Log\Logger($profiler);
$logger->warning('This is a warning!', ['some' => 'context']);
$logger->debug('Some debugging information', ['query' => ['user' => 12345], 'foo' => 'bar']);

Adapters and Decorators

Doctrine

To profile all SQL queries made by Doctrine, you just have to register the SQLLogger adapter in your Doctrine configuration, for example in your bootstrap.php like that:, (*19)

$sqlLogger = new Fabfuel\Prophiler\Adapter\Doctrine\SQLLogger($profiler);
$entityManager->getConnection()->getConfiguration()->setSQLLogger($sqlLogger);

PDO

To profile your PDO database actions, you can use the Prophiler PDO decorator. It will record all query() & exec() calls and prepared statements as well. Just decorate your PDO instance with the Prophiler decorator and use that instead:, (*20)

$pdo = new PDO('mysql:host=localhost;dbname=test', 'user', 'password');
$db = new \Fabfuel\Prophiler\Decorator\PDO\PDO($pdo, $profiler);

$db->query('SELECT * from users');
$db->exec('DELETE FROM users WHERE active = 0');
$db->prepare('SELECT * from users WHERE userId = ?');

Cache

To profile Phalcon cache backend requests, you only need to decorate the cache backend with the BackendDecorator. It will benchmark all cache operations automatically. Here is an example with the APC backend:, (*21)

$cacheFrontend = new \Phalcon\Cache\Frontend\Data(['lifetime' => 172800]);
$cacheBackend = new \Phalcon\Cache\Backend\Apc($cacheFrontend, ['prefix' => 'app-data']);

$cache = \Fabfuel\Prophiler\Decorator\Phalcon\Cache\BackendDecorator($cacheBackend, $profiler);

Elasticsearch

To profile Elasticsearch requests, you only need to decorate the Elasticsearch client with the ClientDecorator:, (*22)

$elasticsearch = new Elasticsearch\Client(['your' => 'config']);
$client = new \Fabfuel\Prophiler\Decorator\Elasticsearch\ClientDecorator($client, $profiler);

Tips

Record session writing

To record session writing, you can commit (this is also known as session_write_close()) the session before rendering the toolbar, (*23)

session_commit();

The Versions

16/09 2017

dev-master

9999999-dev

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Fabian Fuelling

16/09 2017

1.6.0

1.6.0.0

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Fabian Fuelling

16/09 2017

dev-develop

dev-develop

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Fabian Fuelling

16/09 2017

dev-release/1.6.0

dev-release/1.6.0

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Fabian Fuelling

13/11 2015

dev-feature/php7

dev-feature/php7

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Fabian Fuelling

25/10 2015

1.5.0

1.5.0.0

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Fabian Fuelling

08/08 2015

1.4.0

1.4.0.0

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Fabian Fuelling

09/05 2015

1.3.1

1.3.1.0

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Fabian Fuelling

23/04 2015

1.3.0

1.3.0.0

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

  • php ~5.4

 

The Development Requires

by Fabian Fuelling

18/12 2014

1.2.0

1.2.0.0

PHP Profiler & Developer Toolbar built for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

  • php ~5.4

 

The Development Requires

by Fabian Fuelling

29/11 2014

1.1.0

1.1.0.0

Phalcon profiler including dev toolbar

  Sources   Download

BSD-3-Clause

The Requires

  • php ~5.4

 

The Development Requires

by Fabian Fuelling

27/11 2014

1.0.1

1.0.1.0

Phalcon profiler including dev toolbar

  Sources   Download

BSD-3-Clause

The Requires

  • php ~5.4

 

The Development Requires

by Fabian Fuelling

25/11 2014

1.0.0

1.0.0.0

Phalcon profiler including dev toolbar

  Sources   Download

BSD-3-Clause

The Development Requires

by Fabian Fuelling

13/11 2014

0.1.0

0.1.0.0

Phalcon profiler including dev toolbar

  Sources   Download

proprietary

The Development Requires

by Fabian Fuelling