Reputation: 67
I'm trying to get the load time of my page in Symfony 2 with the associated route/url, i want to log all these information in my database or in a file.
For this i want to use the app_dev.php debug toolbar, where all this information are written but i can't access to them ! I found there are "DataCollector" but nothing else to grab it ...
In Symfony/src/Symfony/bundle/frameworkBundle/ressources/config/collectors.xml i found
<service id="data_collector.time" class="%data_collector.time.class%" public="false">
<tag name="data_collector" template="@WebProfiler/Collector/time.html.twig" id="time" priority="255" />
<argument type="service" id="kernel" on-invalid="ignore" />
</service>
Can i do smoething with this service ?
I Found another way :
$this->container->get('profiler')->get('time');
But i have only a starttime not a load time !
Could someone help me about this ? Thanks a lot !
Upvotes: 0
Views: 115
Reputation: 4107
You could solve this problem in a different way. The required information can be easily obtained in the front controller:
<?php
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
$start = microtime(true);
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
$finish = microtime(true);
$elapsedTime = $finish - $start;
$uri = $request->getUri();
// ... insert the URI and the elapsed time in the database
Upvotes: 1