我需要检查在Symfony2应用程序的生产环境中执行了多少sql查询。
我在我的控制器中试过跟踪,但它显示了编码的字符串作为结果。
<?php
.....
.....
.....
class DefaultController extends Controller
{
/**
* @Route("/")
* @Template()
*/
public function testAction()
{
$profile = $this->container->get('profiler')->loadProfile($token);
$data = $this->container->get('profiler')->export($profile);
print_r($data);
}
}
.....
.....
答案 0 :(得分:2)
不建议在生产环境中启用探查器,但是......
进入控制器操作,您可以执行以下操作
$profiler = $this->container->get('profiler');
$profile = $profiler->loadProfile($token);
$queries = $profile->getCollector('db')->getQueries();
echo count($queries); //echo is just an example, you could - of course -
//use something like a logger