Question

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.

No correct solution

OTHER TIPS

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

     ...

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top