You are browsing the Symfony 4 documentation, which changes significantly from Symfony 3.x. If your app doesn't use Symfony 4 yet, browse the Symfony 3.4 documentation.
How to Access Profiling Data Programmatically
How to Access Profiling Data Programmatically¶
Most of the times, the profiler information is accessed and analyzed using its
web-based visualizer. However, you can also retrieve profiling information
programmatically thanks to the methods provided by the
When the response object is available, use the
method to access to its associated profile:
// ... $profiler is the 'profiler' service $profile = $profiler->loadProfileFromResponse($response);
When the profiler stores data about a request, it also associates a token with it;
this token is available in the
X-Debug-Token HTTP header of the response.
Using this token, you can access the profile of any past response thanks to the
$token = $response->headers->get('X-Debug-Token'); $profile = $profiler->loadProfile($token);
When the profiler is enabled but not the web debug toolbar, inspect the page
with your browser's developer tools to get the value of the
profiler service also provides the
find() method to
look for tokens based on some criteria:
1 2 3 4 5 6 7 8 9 10 11
// get the latest 10 tokens $tokens = $profiler->find('', '', 10, '', '', ''); // get the latest 10 tokens for all URL containing /admin/ $tokens = $profiler->find('', '/admin/', 10, '', '', ''); // get the latest 10 tokens for local POST requests $tokens = $profiler->find('127.0.0.1', '', 10, 'POST', '', ''); // get the latest 10 tokens for requests that happened between 2 and 4 days ago $tokens = $profiler->find('', '', 10, '', '4 days ago', '2 days ago');
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.