bi0r0b0t/silex-pinba-provider

Provide PinbaBundle for Silex

1.0.7 2018-06-20 14:29 UTC

This package is auto-updated.

Last update: 2024-03-29 03:31:37 UTC


README

Provide PinbaBundle functionality for Silex

Scrutinizer Code Quality Build Status

Installation

For Silex 2.0

    composer require bi0r0b0t/silex-pinba-provider

or Require the bundle in your composer.json file:

{
    "require": {
        "bi0r0b0t/silex-pinba-provider": "~1.0",
    }
}

For Silex 1.0

Through Composer as bi0r0b0t/silex-pinba-provider .

Require the bundle in your composer.json file:

{
    "require": {
        "bi0r0b0t/silex-pinba-provider": "~0.1",
    }
}

Register

Important! Register the bundle in prod environment after TwigServiceProvider and DoctrineServiceProvider:

/**
 * @var $app Silex\Application
 */
$app->register(new SilexPinbaProvider\SilexPinbaProvider()

Using with Doctrine ORM

Examples based on dflydev/doctrine-orm-service-provider

Collecting Filesystem metrics

/**
 * @var $app Silex\Application
 */
$app['orm.cache.factory.filesystem'] = $app->protect(function($cacheOptions) use ($app) {
    if (empty($cacheOptions['path'])) {
        throw new \RuntimeException('FilesystemCache path not defined');
    }
    $cache = new  SilexPinbaProvider\Cache\Filesystem($cacheOptions['path']);
    $cache->setStopwatch($app['intaro_pinba.stopwatch']);
    return $cache;
});

Collecting Memcache metrics

/**
 * @var $app Silex\Application
 */
$app['orm.cache.factory.backing_memcache'] = $app->protect(function() use ($app) {
   $cache = new Intaro\PinbaBundle\Cache\Memcache();
   $cache->setStopwatch($app['intaro_pinba.stopwatch']);
   return $cache;
});

Using with console

/**
 * @var $console Symfony\Component\Console\Application
 * @var $app     Silex\Application
 */
if (function_exists('pinba_script_name_set')) {
    pinba_script_name_set('console');
    $input = new Symfony\Component\Console\Input\ArgvInput();
    $timer = pinba_timer_start(array(
        'server'  => $app['intaro_pinba.server.name'],
        'group'   => 'console::run',
        'command' => $input->getFirstArgument(),
    ));
    $res = $console->run($input);
    pinba_timer_stop($timer);
    return $res;
} else {
    return $console->run();
}