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.
Learn how to use Doctrine Doctor effectively in your Symfony project.
The Doctrine Doctor panel appears in the Symfony Web Profiler toolbar after each request.
The panel displays:
critical, warning, info)Each issue contains:
🔴 Critical: N+1 Query Detected
Detailed explanation of the problem and its impact.
The specific SQL queries involved:
SELECT * FROM user WHERE id = ?
-- Executed 100 times
Code location where the query originated:
src/Controller/UserController.php:42
templates/user/index.html.twig:15
Actionable solution with code example:
$users = $repository
->createQueryBuilder('u')
->leftJoin('u.profile', 'p')
->addSelect('p')
->getQuery()
->getResult();
Write your Symfony code without worrying about Doctrine Doctor.
After loading a page, click the Doctrine Doctor panel in the profiler.
Focus on Critical issues first, then Warning issues.
Use the provided code examples to fix issues.
Refresh the page and confirm the issue is resolved.
Customize analyzer behavior in config/packages/dev/doctrine_doctor.yaml:
doctrine_doctor:
analyzers:
n_plus_one:
threshold: 2 # Detect even minor N+1 issues
doctrine_doctor:
analyzers:
slow_query:
threshold: 50 # Flag queries over 50ms
[See full configuration reference →]({{ site.baseurl }}/user-guide/configuration)
Action: Fix immediately before committing
Action: Fix before merging to main branch
Action: Plan and address progressively
How can I help you explore Laravel packages today?