bi0r0b0t / silex-pinba-provider
为 Silex 提供 PinbaBundle
1.0.7
2018-06-20 14:29 UTC
Requires
- doctrine/dbal: ~2.2
- intaro/pinba-bundle: ~0.4.2
- silex/silex: ~2.0
- twig/twig: ^2.0
Requires (Dev)
- gggeek/pinba_php: dev-master#d23c3725a19d53a6f98f91673d73e8f685f6f3d7
- misterion/pinba-phpdoc: dev-master
- phpunit/phpunit: ^6.4
README
为 PinbaBundle 功能提供 Silex
安装
对于 Silex 2.0
composer require bi0r0b0t/silex-pinba-provider
或在您的 composer.json
文件中要求捆绑包
{ "require": { "bi0r0b0t/silex-pinba-provider": "~1.0", } }
对于 Silex 1.0
通过 Composer 作为 bi0r0b0t/silex-pinba-provider .
在您的 composer.json
文件中要求捆绑包
{ "require": { "bi0r0b0t/silex-pinba-provider": "~0.1", } }
注册
重要! 在 TwigServiceProvider 和 DoctrineServiceProvider 之后在 prod
环境中注册捆绑包
/** * @var $app Silex\Application */ $app->register(new SilexPinbaProvider\SilexPinbaProvider()
与 Doctrine ORM 一起使用
基于 dflydev/doctrine-orm-service-provider 的示例
收集文件系统指标
/** * @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; });
收集 Memcache 指标
/** * @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; });
与控制台一起使用
/** * @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(); }