dek-cz/mssql-profiler-bundle
Install the Package
composer require --dev dek-cz/mssql-profiler-bundle
Add to config/bundles.php (for Laravel 8+):
Dekcz\MssqlProfiler\MssqlProfilerBundle::class => ['dev' => true, 'test' => true],
Configure the Bundle
Create config/packages/dev/mssql_profiler.yaml (or test/):
mssql_profiler:
web_profiler: true
client_definition: 'App\Services\MssqlConnector' # Your custom connector class
Implement the Collector Interface
Create a custom connector (e.g., app/Services/MssqlConnector.php):
use Dekcz\MssqlProfiler\DataCollector\MssqlCollectorInterface;
use Dekcz\MssqlProfiler\DataCollector\MssqlCollectorTrait;
class MssqlConnector implements MssqlCollectorInterface
{
use MssqlCollectorTrait;
// Override methods to inject your DB connection logic
public function getConnection(): \PDO
{
return \DB::connection('sqlsrv')->getPdo();
}
}
First Use Case
Run a Laravel app in dev mode (APP_ENV=dev) and visit /_profiler. The toolbar will now include an MSSQL Procedures tab, showing stored procedure calls.
Database Connection Handling
DB facade or a custom connection (e.g., sqlsrv).getConnection() in your collector to return the correct \PDO instance.public function getConnection(): \PDO
{
return \DB::connection('sqlsrv')->getPdo();
}
Query Logging
EXEC sp_name).PDO::MYSQL_ATTR_INIT_COMMAND or middleware).Environment-Specific Activation
dev/test environments via bundles.php and mssql_profiler.yaml.Custom Data Collection
MssqlCollectorTrait to add custom metrics (e.g., execution time, parameters).public function collect(\Symfony\Component\HttpFoundation\Request $request)
{
$this->startCollection();
// Your custom logic (e.g., log slow procedures)
$this->stopCollection();
}
Toolbar Integration
Connection Issues
getConnection() returns null, the profiler will show no data.Stored Procedure Filtering
sp_who2).shouldCollect():
public function shouldCollect(string $procedureName): bool
{
return !str_starts_with($procedureName, 'sp_');
}
Performance Overhead
production via bundles.php.Missing Data in Profiler
client_definition in mssql_profiler.yaml points to a valid class.PDO_SQLSRV).web_profiler is set to true.Log Collector Events Add debug logs in your collector:
public function collect(\Symfony\Component\HttpFoundation\Request $request)
{
\Log::debug('MSSQL Profiler: Starting collection');
$this->startCollection();
// ...
}
Verify PDO Driver Ensure your PDO driver supports procedure logging:
$pdo = \DB::connection('sqlsrv')->getPdo();
\Log::debug('PDO Driver:', [$pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)]);
Clear Cache After changes, run:
php artisan config:clear
php artisan cache:clear
Custom Procedure Metadata Extend the trait to fetch additional details (e.g., parameter values):
public function getProcedureMetadata(string $procedureName): array
{
$metadata = parent::getProcedureMetadata($procedureName);
$metadata['custom_field'] = $this->fetchCustomData($procedureName);
return $metadata;
}
Visual Customization Override the Twig template for the profiler panel:
vendor/dekcz/mssql-profiler-bundle/resources/views/profiler.html.twig to resources/views/vendor/mssql_profiler/profiler.html.twig.Integration with Laravel Debugbar
If using barryvdh/laravel-debugbar, merge MSSQL data into the existing panel:
public function collect(\Symfony\Component\HttpFoundation\Request $request)
{
$this->startCollection();
$data = $this->getCollectedData();
\Debugbar::addCollector(new MssqlDebugbarCollector($data));
}
How can I help you explore Laravel packages today?