8000 added a cookbook about debugging · symfony/symfony-docs@b85bac6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b85bac6

Browse files
committed
added a cookbook about debugging
1 parent 3996af4 commit b85bac6

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

cookbook/debugging.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
How to optimize your development Environment for debugging
2+
==========================================================
3+
4+
When you work on a Symfony project on your local machine, you should use the
5+
``dev`` environment (``app_dev.php`` front controller). This environment
6+
configuration is optimized for two main purposes:
7+
8+
* Give the developer accurate feedback whenever something goes wrong (web
9+
debug toolbar, nice exception pages, profiler, ...);
10+
11+
* Be as similar as possible as the production environment to avoid problems
12+
when deploying the project.
13+
14+
And to make the production environment as fast as possible, Symfony creates
15+
big PHP files in your cache containing the aggregation of PHP classes your
16+
project needs for every request. However, this behavior can confuse your IDE
17+
or your debugger. This recipe shows you how you can tweak this caching
18+
mechanism to make it friendlier when you need to debug code that involves
19+
Symfony classes.
20+
21+
The ``app_dev.php`` front controller reads as follows by default::
22+
23+
// ...
24+
25+
require_once __DIR__.'/../app/bootstrap.php.cache';
26+
require_once __DIR__.'/../app/AppKernel.php';
27+
28+
use Symfony\Component\HttpFoundation\Request;
29+
30+
$kernel = new AppKernel('dev', true);
31+
$kernel->loadClassCache();
32+
$kernel->handle(Request::createFromGlobals())->send();
33+
34+
To make you debugger happier, disable all PHP class caches by removing the
35+
call to ``loadClassCache()`` and by replacing the require statements like
36+
below::
37+
38+
// ...
39+
40+
// require_once __DIR__.'/../app/bootstrap.php.cache';
41+
require_once __DIR__.'/../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
42+
require_once __DIR__.'/../app/autoload.php';
43+
require_once __DIR__.'/../app/AppKernel.php';
44+
45+
use Symfony\Component\HttpFoundation\Request;
46+
47+
$kernel = new AppKernel('dev', true);
48+
// $kernel->loadClassCache();
49+
$kernel->handle(Request::createFromGlobals())->send();
50+
51+
.. tip::
52+
53+
If you disable the PHP caches, don't forget to revert after your debugging
54+
session.
55+
56+
Some IDEs do not like the fact that some classes are stored in different
57+
locations. To avoid problems, you can either tell your IDE to ignore the PHP
58+
cache files, or you can change the extension used by Symfony for these files::
59+
60+
$kernel->loadClassCache('classes', '.php.cache');

cookbook/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Cookbook
2929
doctrine/mongodb
3030
doctrine/migrations
3131
routing/scheme
32+
debugging
3233
symfony1
3334

3435
.. include:: map.rst.inc

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
* :doc:`/cookbook/doctrine/doctrine_fixtures`
2323
* :doc:`/cookbook/doctrine/mongodb`
2424
* :doc:`/cookbook/routing/scheme`
25+
* :doc:`/cookbook/debugging`
2526
* :doc:`/ 331F cookbook/symfony1`

0 commit comments

Comments
 (0)
0