Search code examples
phpsymfony1doctrinesymfony-1.4profiler

How can I access the Doctrine profiler in production environment?


I have a filter set up to count the number of queries executed and write something to my database if they exceed a certain limit.

It works fine in my development environment, but when I test it in my production environment my database doesn't return a profiler anymore. I suposse it is a setting which enables the database profiler for the development environment, but I can' seem to find it.

I use Symfony1.4 and Doctrine.

$database = $databaseManager->getDatabase($name);
if ($database instanceof sfDoctrineDatabase && $profiler = $database->getProfiler())
{
    $events = $profiler->getQueryExecutionEvents();
}

Solution

  • You can force the profiler for a connection inside your database.yml with the profiler option:

    prod:
      master:
        class: sfDoctrineDatabase
        param:
          profiler: true
          dsn: 'mysql:host=localhost;dbname=dbname'
          username: username
          password: password
    

    Indicates whether to output doctrine log to the debug toolbar. The default value of profiler depends on the environment. In development environment the default value is true, otherwise - false.