@@ -119,10 +119,10 @@ need to create a custom data collector. Instead, use the built-in utilities to
119
119
Consider using a professional profiler such as `Blackfire `_ to measure and
120
120
analyze the execution of your application in detail.
121
121
122
- .. _enabling-the-profiler-conditionally :
122
+ .. _enabling-the-profiler-programmatically :
123
123
124
- Enabling the Profiler Programmatically
125
- --------------------------------------
124
+ Enabling the Profiler Programmatically or Conditionally
125
+ -------------------------------------------------------
126
126
127
127
Symfony Profiler can be enabled and disabled programmatically. You can use the ``enable() ``
128
128
and ``disable() `` methods of the :class: `Symfony\\ Component\\ HttpKernel\\ Profiler\\ Profiler `
@@ -179,6 +179,31 @@ create an alias pointing to the existing ``profiler`` service:
179
179
180
180
$container->setAlias(Profiler::class, 'profiler');
181
181
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
+
182
207
Updating the Web Debug Toolbar After AJAX Requests
183
208
--------------------------------------------------
184
209
0 commit comments