Skip to content

Commit 017182f

Browse files
committed
Bootstrap main debugging guide
1 parent 09cc5fc commit 017182f

File tree

3 files changed

+86
-95
lines changed

3 files changed

+86
-95
lines changed

_build/redirection_map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,5 @@
324324
/components/yaml/index /components/yaml
325325
/deployment/tools /deployment
326326
/install/bundles /setup/bundles
327+
/debug/debugging /debug
327328
/form /forms

debug.rst

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,87 @@
1-
Debugging
2-
=========
1+
.. index::
2+
single: Debugging
33

4-
.. toctree::
5-
:maxdepth: 1
6-
:glob:
4+
How to Optimize your Development Environment for Debugging
5+
==========================================================
76

8-
debug/*
7+
When you work on a Symfony project on your local machine, you should use the
8+
``dev`` environment (``app_dev.php`` front controller). This environment
9+
configuration is optimized for two main purposes.
10+
11+
* Give the developer accurate feedback whenever something goes wrong (provided
12+
by the web debug toolbar, nice exception pages, profiler, ...);
13+
* Be as similar as possible as the production environment to avoid problems
14+
when deploying the project.
15+
16+
Disabling the Bootstrap File and Class Caching
17+
----------------------------------------------
18+
19+
To make Symfony run as fast as possible, it creates big PHP files in your cache
20+
containing the aggregation of PHP classes your project needs for every request.
21+
However, this behavior can confuse your IDE or your debugger. This recipe shows
22+
you how you can tweak this caching mechanism to make it friendlier when you
23+
need to debug code that involves Symfony classes.
24+
25+
The ``app_dev.php`` front controller reads as follows by default::
26+
27+
// ...
28+
29+
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
30+
require_once __DIR__.'/../app/AppKernel.php';
31+
32+
$kernel = new AppKernel('dev', true);
33+
$kernel->loadClassCache();
34+
$request = Request::createFromGlobals();
35+
36+
To make your debugger happier, disable all PHP class caches by removing the
37+
call to ``loadClassCache()`` and by replacing the require statements like
38+
below::
39+
40+
// ...
41+
42+
// $loader = require_once __DIR__.'/../app/bootstrap.php.cache';
43+
$loader = require_once __DIR__.'/../app/autoload.php';
44+
require_once __DIR__.'/../app/AppKernel.php';
45+
46+
$kernel = new AppKernel('dev', true);
47+
// $kernel->loadClassCache();
48+
$request = Request::createFromGlobals();
49+
50+
.. tip::
51+
52+
If you disable the PHP caches, don't forget to revert after your debugging
53+
session.
54+
55+
Some IDEs do not like the fact that some classes are stored in different
56+
locations. To avoid problems, you can either tell your IDE to ignore the PHP
57+
cache files, or you can change the extension used by Symfony for these files::
58+
59+
$kernel->loadClassCache('classes', '.php.cache');
60+
61+
Useful Debugging Commands
62+
-------------------------
63+
64+
When developing a large application, it can be hard to keep track of all the
65+
different services, routes and translations. Luckily, Symfony has some commands
66+
that can help you visualize and find the information.
67+
68+
``debug:container``
69+
Displays information about the contents of the Symfony container for all public
70+
services. To find only those matching a name, append the name as an argument.
71+
72+
``debug:config``
73+
Shows all configured bundles, their class and their alias.
74+
75+
``debug:router``
76+
Displays information about all configured routes in the application as a
77+
table with the name, method, scheme, host and path for each route.
78+
79+
``debug:translation <locale>``
80+
Shows a table of the translation key, the domain, the translation and the
81+
fallback translation for all known messages, if translations exist for
82+
the given locale.
83+
84+
.. tip::
85+
86+
When in doubt how to use a console command, open the help section by
87+
appending the ``--help`` option.

debug/debugging.rst

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)