Some months ago, I wrote a post in Spanish about debugging Symfony apps with Xdebug with the hope that I would translate it to English soon. Well, not as soon as I wished,but here is it.
Whe I started to work with the Symfony standard distribution, 18 months ago (I used to work with Zend Framework 1 before), I didn’t understand the event controlled execution flow (beside other dark magics inside the framework), so the first thing I tried was to debug a full request with the help of Xdebug.
The problem was that, although I set the breakpoints in every interesting line of code, these breakpoints were completely ignored. The reason, easy to understand now than I know it, was that the files with the breakpoints were never executed. They were being cached to another location to accelerate the framework and this location was hidden for mi IDE.
To simplify my debugging work of the hidden corners of the framework, without the need of setting breakpoints it those cache files, the solution was to skip the cache files with a comment to the $kernel->loadClassCache(); inside the web/app_dev.php file. But I wanted to avoid the cache only when the Xdebug session was running, so I wrote a little conditional expression to detect it.
Here is the snippet that helped me a lot to understand how Symfony works:
//This check tries to detect a Xdebug session to prevent the load of class cache
if (
!extension_loaded('xdebug') ||
(
!isset($_REQUEST['XDEBUG_SESSION_START']) &&
!isset($_COOKIE['XDEBUG_SESSION']) &&
ini_get('xdebug.remote_autostart') == false
)
) {
$kernel->loadClassCache();
}
Any typo or problem? Edit this page on Github