PHP code example of fabfuel / prophiler

1. Go to this page and download the library: Download fabfuel/prophiler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fabfuel / prophiler example snippets


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

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

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

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

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

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

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

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

$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']);

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

$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 = ?');

$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 = new Elasticsearch\Client(['your' => 'config']);
$client = new \Fabfuel\Prophiler\Decorator\Elasticsearch\ClientDecorator($client, $profiler);

session_commit();