I found a way that I think is appropriate for our use case. I created a new performance.php file in a web folder that looks like this:
<?php
$GLOBALS['PerformanceTwigExtensionMicrotime'] = microtime(true);
require_once __DIR__.'/app.php';
, :
<?php
namespace Acme\DemoBundle\Extension;
class PerformanceTwigExtension extends \Twig_Extension {
public function getFunctions() {
return array(
'performance_exectime' => new \Twig_Function_Method($this, 'getExecTime')
);
}
public function getExecTime() {
if (!isset($GLOBALS['PerformanceTwigExtensionMicrotime'])) {
return 0;
}
$durationInMilliseconds = (microtime(true) - $GLOBALS['PerformanceTwigExtensionMicrotime']) * 1000;
return number_format($durationInMilliseconds, 3, '.', '');
}
public function getName() {
return "performance_extension";
}
}
, performance.php. :
{{ performance_exectime() }}
0, (, app.php), . , - performance.php , , .