Skip to content

Commit 81a6e1a

Browse files
committed
Tweaks
1 parent 723fe9e commit 81a6e1a

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

profiler.rst

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

113-
.. _enabling-the-profiler-conditionally:
113+
.. _enabling-the-profiler-programmatically:
114114

115-
Enabling the Profiler Programmatically
116-
--------------------------------------
115+
Enabling the Profiler Programmatically or Conditionally
116+
-------------------------------------------------------
117117

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

@@ -523,27 +548,6 @@ you'll need to configure the data collector explicitly:
523548
// 'priority' => 300,
524549
]);
525550
};
526-
527-
Conditional Profiling
528-
~~~~~~~~~~~~~~~~~~~~~
529-
530-
Symfony profiler provides an immense amount of debug information to quickly find the cause of any problem. However, that comes at a price, because the profiler must collect all that information while serving the request. This can slowdown the application even for requests where you don't look at the profiler information (which are most of them).
531-
532-
You can enable the profiler conditionally. To do that, add these two new config options:
533-
534-
.. configuration-block::
535-
536-
.. code-block:: yaml
537-
538-
# config/packages/dev/web_profiler.yaml
539-
framework:
540-
profiler:
541-
collect: false
542-
collect_parameter: 'profile'
543-
544-
The collect: false option disables the profiler by default and the collect_parameter: profile option enables it for requests that include the profile query parameter.
545-
546-
You can freely choose the query parameter name and you can also enable the profiler by submitting a form field with that name (useful for POST requests) and even a request attribute.
547551
548552
.. _`Single-page applications`: https://en.wikipedia.org/wiki/Single-page_application
549553
.. _`Blackfire`: https://blackfire.io/docs/introduction?utm_source=symfony&utm_medium=symfonycom_docs&utm_campaign=profiler

0 commit comments

Comments
 (0)