Installation Add the bundle via Composer:
composer require clamidity/profiler-bundle
Enable it in config/bundles.php:
return [
// ...
Clamidity\ProfilerBundle\ClamidityProfilerBundle::class => ['all' => true],
];
First Use Case
Enable XHProf in config/packages/clamidity_profiler.yaml:
clamidity_profiler:
enabled: true
xhprof:
enabled: true
Clear cache:
php bin/console cache:clear
Access /_profiler to see XHProf data alongside Symfony’s built-in profiler.
Debugging Slow Endpoints
/api/users before/after a database optimization.Integration with Symfony Profiler
Request, Doctrine).ProfilerListener to attach XHProf data to Symfony’s DataCollector.Conditional Profiling
clamidity_profiler:
enabled: '%kernel.debug%' # Only active in dev
Custom Data Collection
Clamidity\ProfilerBundle\DataCollector\XhprofDataCollector.$profiler->addCustomData('user_action', 'login');
stof/doctrine-extensions to profile QueryBuilder calls.HttpKernel event listener to profile only specific routes:
clamidity_profiler:
xhprof:
enabled_routes: ['^/api/']
Performance Overhead
enabled: false
xhprof_disable() in critical paths (e.g., CLI commands).Memory Leaks
$profiler->clear();
Symfony 5+ Compatibility
symfony/profiler-pack instead.extension=xhprof.so is loaded in php.ini.clamidity_profiler.yaml (YAML is strict).var/log/dev.log.Custom Storage Override the storage adapter to save XHProf data to a database:
// src/Profiler/XhprofStorage.php
class CustomXhprofStorage extends \Clamidity\ProfilerBundle\Storage\XhprofStorage
{
public function save($data) {
// Save to DB instead of file
}
}
Register in services.yaml:
Clamidity\ProfilerBundle\Storage\XhprofStorage: '@App\Profiler\CustomXhprofStorage'
UI Customization
Extend the Twig templates in templates/bundles/clamidityprofiler/ to modify the profiler UI.
Asynchronous Profiling
Use the ProfilerEvent to profile background jobs (e.g., Symfony Messenger):
// src/EventListener/ProfilerListener.php
public function onMessage(WorkerMessageEvent $event) {
if ($event->getMessage() instanceof YourMessage) {
$profiler->start('message_processing');
// Process message
$profiler->stop('message_processing');
}
}
How can I help you explore Laravel packages today?