srgiz / phalcon-profiler
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/srgiz/phalcon-profiler
Requires
- php: >=8.0
- ext-phalcon: ^5.1
- ext-xmlreader: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- phalcon/ide-stubs: v5.1.4
- phpunit/phpunit: ^9.6
- vimeo/psalm: ^5.13
This package is auto-updated.
Last update: 2025-12-31 00:28:44 UTC
README
Supports micro and classic app.
composer require --dev srgiz/phalcon-profiler
- PHP >= 8.0
- Phalcon >= 5.1
Install
Di:
# Phalcon\Mvc\Application use Phalcon\Di\DiInterface; use Phalcon\Mvc\Application; use Srgiz\Phalcon\WebProfiler\WebProfiler; /** @var DiInterface $di */ if ('dev' === $env) { $di->register(new WebProfiler()); } $application = new Application($di); $application->setEventsManager($di->getShared('eventsManager'));
# Phalcon\Mvc\Micro use Phalcon\Di\DiInterface; use Phalcon\Mvc\Micro; use Srgiz\Phalcon\WebProfiler\WebProfiler; /** @var DiInterface $di */ if ('dev' === $env) { $di->register(new WebProfiler()); } $app = new Micro($di); $app->setEventsManager($di->getShared('eventsManager'));
Configure eventsManager:
eventsManager: className: Phalcon\Events\Manager calls: - method: enablePriorities arguments: - { type: parameter, value: true }
Enable events in services:
dispatcher: db: view: volt: calls: - method: setEventsManager arguments: - { type: service, name: eventsManager }
Profiler config
// ./config/config.php return [ 'profiler' => [ 'viewsCachePath' => '/var/www/var/cache/volt/', 'tagsDir' => '/var/www/var/profiler', //'routePrefix' => '/_profiler', //'collectors' => [ /** @see \Srgiz\Phalcon\WebProfiler\Collector\CollectorInterface */ // CustomCollector::class, //], ], ];
Toolbar
{# layout.volt #}
<body>
content
{% if _profilerTag is defined %}
<script>
document.addEventListener('DOMContentLoaded', function () {
fetch('{{ url(['for': '_profiler-bar', 'tag': _profilerTag])|escape_js }}')
.then(function(res) { return res.text() })
.then(function(data) {
document.body.innerHTML += data
})
.catch(function(e) {
console.error(e)
})
})
</script>
{% endif %}
</body>
Logger
Create a logger adapter:
$container->setShared('devLoggerAdapter', function () use ($container) { return $container->has('profilerLoggerAdapter') ? $container->getShared('profilerLoggerAdapter') : new \Phalcon\Logger\Adapter\Noop(); });
Usage:
logger: className: Phalcon\Logger\Logger shared: true arguments: - { type: parameter, value: main } calls: - method: addAdapter arguments: - { type: parameter, value: profiler } - { type: service, name: devLoggerAdapter }
Stopwatch in production
Create a stopwatch adapter:
use Phalcon\Di\DiInterface; use Phalcon\Di\ServiceProviderInterface; class StopwatchProvider implements ServiceProviderInterface { public function register(DiInterface $di): void { $di->setShared('stopwatch', function () use ($di) { return $di->has('profilerStopwatch') ? $di->getShared('profilerStopwatch') : null; }); } }
Usage:
$di->get('stopwatch')?->start('test'); // ... $di->get('stopwatch')?->stop('test');
Custom collector
use Srgiz\Phalcon\WebProfiler\Collector\CollectorInterface; class CustomCollector implements CollectorInterface { public function templatePath(): string { return '/var/www/templates/custom'; // .volt } public function name(): string { return 'Custom'; } public function collect(): array { return [ 'message' => 'hello', ]; } }
{# custom.volt #}
{% extends '@profiler/data.volt' %}
{% block panel %}
Message: {{ message|e }}
{% endblock %}

