I need to get symfony2 application execution time in twig or controller, and to store it in mysql database. How I can do this? It is available in web profiler toolbar, but I don't know how to access it.
1 Answer
If you're only accounting for the time the controller takes, you can use the Stopwatch component:
http://symfony.com/doc/current/components/stopwatch.html
use Symfony\Component\Stopwatch\Stopwatch;
public function indexAction()
{
$stopwatch = new Stopwatch();
// Start event named 'eventName'
$stopwatch->start('eventName');
// ... some code goes here
$event = $stopwatch->stop('eventName');
// get total duration (but see the docs for more info)
$timeTaken = $event->getDuration(); // Returns the event duration, including all periods
...
}
devandprodenvironments? Since the toolbar is only present indevenvironment, you'll have to find another way.