Making Doctrine and Symfony Logged Queries Runnable

On many of our projects we use Gearman to do background processing.  One of problems with doing things in the background is that the web debug toolbar isn’t available to help with debugging problems, including queries.  Normally when you want to see your queries you can look at the debug toolbar and get a runnable version of the query quickly.  However, when its running in the background, you have to look at the application logs to see what the query is.  The logs don’t contain a runnable format of the query, for example they may look like this:

Problem is you can’t quickly take that to your database and run it to see the results. Plugging in the parameters is easy enough, but it takes time. I decided to quickly whip up a script that will take what is in the gist above and convert it to a runnable format. I’ve posted this over at http://code.setfive.com/doctrine-query-log-converter/ . This hopefully will save you some time when you are trying to debug your background processes.

It should work with both Doctrine 1.x/symfony 1.x and Doctrine2.x/Symfony2.x. If you find any issues with it let me know.

Good luck debugging!

Posted In: Doctrine, PHP, Symfony, Tips n' Tricks

Tags: , , , , ,

  • Or you can use this that I made. https://github.com/phpexpertsinc/DoctrineDetective

  • Theodore – cool bundle! That’d work if we were making requests each time. The use case for this is when you’ve made a request lets say to start a background report. The request will finish completely before the report has even begun to be ran. We queue the report in gearman, where later a worker will process it, so we don’t have any response from the backend worker. All there is are some logs of the queries it executed while running.

    This is the use case we’re trying to solve. In recent versions of Symfony2 they make it really easy to get the profile from an ajax request directly from the toolbar so usually use that.

    Regardless, your bundle definitely looks great I hadn’t seen it before. Thanks!

  • Ross Cousens

    I just turn on a queries log on the DB and capture the query I’m interested in.