Skip to content

Commit 4e970cb

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: [Profiler] Add conditional profiling example config
2 parents f874038 + 81a6e1a commit 4e970cb

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

profiler.rst

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ need to create a custom data collector. Instead, use the built-in utilities to
119119
Consider using a professional profiler such as `Blackfire`_ to measure and
120120
analyze the execution of your application in detail.
121121

122-
.. _enabling-the-profiler-conditionally:
122+
.. _enabling-the-profiler-programmatically:
123123

124-
Enabling the Profiler Programmatically
125-
--------------------------------------
124+
Enabling the Profiler Programmatically or Conditionally
125+
-------------------------------------------------------
126126

127127
Symfony Profiler can be enabled and disabled programmatically. You can use the ``enable()``
128128
and ``disable()`` methods of the :class:`Symfony\\Component\\HttpKernel\\Profiler\\Profiler`
@@ -179,6 +179,31 @@ create an alias pointing to the existing ``profiler`` service:
179179
180180
$container->setAlias(Profiler::class, 'profiler');
181181
182+
.. _enabling-the-profiler-conditionally:
183+
184+
Enabling the Profiler Conditionally
185+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186+
187+
Instead of enabling the profiler programmatically as explained in the previous
188+
section, you can also enable it when a certain condition is met (e.g. a certain
189+
parameter is included in the URL):
190+
191+
.. code-block:: yaml
192+
193+
# config/packages/dev/web_profiler.yaml
194+
framework:
195+
profiler:
196+
collect: false
197+
collect_parameter: 'profile'
198+
199+
This configuration disables the profiler by default (``collect: false``) to
200+
improve the application performance; but enables it for requests that include a
201+
query parameter called ``profile`` (you can freely choose this query parameter name).
202+
203+
In addition to the query parameter, this feature also works when submitting a
204+
form field with that name (useful to enable the profiler in ``POST`` requests)
205+
or when including it as a request attribute.
206+
182207
Updating the Web Debug Toolbar After AJAX Requests
183208
--------------------------------------------------
184209

0 commit comments

Comments
 (0)