Symfony2 get Profile and QueryCount
I needed to get the queries executed until a certain moment and in order to do so we need to get the profiler, to get the actual profile and then look for the data.
I couldn't find anywhere how to do it so I went in the symfony core code to look for the solution and I found that in the WebTestCase it was possible to get that data and it's done as following:
$response = $this->get('kernel')->handle($this->getRequest());
$profiler = $this->container->get('profiler');
$profile = $profiler->loadProfileFromResponse($response);
At this moment we have the actual profile and we look for the data that we want.
For example I need the QueryCount.
$profile->getCollector('db')->getQueryCount();
Written by Gonçalo Margalho
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#