ahmed-bhs/doctrine-doctor
Doctrine Doctor is a runtime analysis tool for Doctrine ORM integrated into the Symfony Web Profiler. It detects real-world issues like N+1 queries, slow queries, missing indexes, hydration overhead, and injection risks, with actionable backtraces and suggestions.
Quick answers to common questions about Doctrine Doctor.
composer require --dev ahmed-bhs/doctrine-doctor
That's it! Auto-configured via Symfony Flex.
Yes! Doctrine Doctor supports:
No configuration required! It works out of the box. Optional configuration available in config/packages/dev/doctrine_doctor.yaml.
dev environmentYes! Enable backtraces:
# config/packages/dev/doctrine.yaml
doctrine:
dbal:
profiling_collect_backtrace: true
# config/packages/dev/doctrine_doctor.yaml
doctrine_doctor:
analyzers:
n_plus_one:
enabled: false
Analysis runs in the Symfony data collector during profiling and is intended for development usage only.
No, never! It's a dev-only tool:
--dev flagprod environmentTypically low overhead in dev; it should remain disabled in production.
90+ specialized analyzers across 4 categories:
Yes! Implement AnalyzerInterface (query-based) or MetadataAnalyzerInterface (metadata-based) and tag with doctrine_doctor.analyzer. [See guide]({{ site.baseurl }}/contributing/creating-analyzers).
Start with:
Check:
dev environmentconfig/bundles.phpphp bin/console cache:clearPossible reasons:
Ensure database user has SELECT permissions. Disable if needed:
doctrine_doctor:
analyzers:
missing_index:
explain_queries: false
Lower thresholds for stricter detection:
doctrine_doctor:
analyzers:
n_plus_one:
threshold: 2 # More strict (default: 5)
slow_query:
threshold: 50 # More strict (default: 100ms)
Yes, enabled by default:
doctrine_doctor:
analysis:
exclude_third_party_entities: true
Different tools, complementary:
| Feature | Doctrine Doctor | PHPStan |
|---|---|---|
| Detects | Runtime issues | Code issues |
| N+1 queries | ✅ Yes | ❌ No |
| Missing indexes | ✅ Yes (real DB) | ❌ No |
| Type errors | ❌ No | ✅ Yes |
| When runs | During requests | CI/pre-commit |
Use both! PHPStan for code quality, Doctrine Doctor for runtime performance.
Doctrine Doctor extends it:
| Feature | Doctrine Panel | Doctrine Doctor |
|---|---|---|
| Query list | ✅ Yes | ✅ Yes |
| Execution time | ✅ Yes | ✅ Yes |
| N+1 detection | ❌ No | ✅ Yes |
| Suggestions | ❌ No | ✅ Yes + code |
| Security checks | ❌ No | ✅ Yes |
| 90+ analyzers | ❌ No | ✅ Yes |
See [Contributing Guide]({{ site.baseurl }}/contributing/overview). Ways to help:
Yes! MIT License - free for commercial use.
Yes! MIT License allows modifications and redistribution.
Still have questions? Open a discussion
How can I help you explore Laravel packages today?