Quick Start

Get Doctrine Doctor running in your Symfony project in under 30 seconds.


Installation

Install via Composer:

composer require --dev ahmed-bhs/doctrine-doctor

Auto-Configuration

Doctrine Doctor is automatically configured via Symfony Flex. No manual setup required!


Verify Installation

  1. Refresh any page in your Symfony application (in dev environment)
  2. Open the Symfony Web Profiler (bottom toolbar)
  3. Look for the “Doctrine Doctor” panel

First Analysis

Doctrine Doctor automatically analyzes all database queries executed during your request.

Example: Detect N+1 Query

Create a simple controller:

<?php

namespace App\Controller;

use App\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class UserController extends AbstractController
{
    #[Route('/users', name: 'app_users')]
    public function index(UserRepository $userRepository): Response
    {
        $users = $userRepository->findAll();

        return $this->render('user/index.html.twig', [
            'users' => $users,
        ]);
    }
}

And a Twig template:

{# templates/user/index.html.twig #}
{% for user in users %}
    <p>{{ user.name }} - {{ user.profile.bio }}</p>
{% endfor %}

Result: Doctrine Doctor will detect the N+1 query issue and suggest using eager loading!


To see exactly WHERE in your code issues originate, enable query backtraces:

# config/packages/dev/doctrine.yaml
doctrine:
    dbal:
        profiling_collect_backtrace: true

Performance Impact: Backtrace collection has minimal overhead (~2-5%) and is recommended for development.


Next Steps