Debugging with Xdebug

How Xdebug Works

Before we set up Xdebug, I want to talk through how it works so the setup makes more sense and it doesn't seem like a series of strange steps.

Before we set up Xde­bug, I want to talk through how it works so the set­up makes more sense and it doesn’t seem like a series of strange steps. Plus, it’s impor­tant to under­stand, at least at a high lev­el, how the tools you use work. 

As I men­tioned in the last video, Xde­bug is a PHP exten­sion and runs on the local serv­er as part of PHP that runs your appli­ca­tion. Our web serv­er that runs the site via PHP would have Xde­bug installed and enabled in order for us to use.

When Xde­bug is run­ning, it will call back to your IDE (like Php­Storm or VS Code) from the serv­er where it’s run­ning. Your IDE will sit and lis­ten for that con­nec­tion on a spe­cif­ic port (typ­i­cal­ly port 9000 or 9003). 

You load a page in the brows­er for your project and when that hap­pens Xde­bug sends a con­nec­tion request to your IDE and says hey, I am get­ting a request, what do you have for me?”. At this point, Xde­bug and your IDE start com­mu­ni­cat­ing via the [[DBGP pro­to­col]]. This sounds fan­cy (and maybe it is) but it’s just a pro­to­col cre­ate by Xde­bug for com­munca­tion between itself and an IDE

Explana­to­ry chart I use in the video via the arti­cle Under­stand­ing XDe­bug using Mes­sage Sequence Charts (msc­gen)

Debugging with Xdebug is made up of the following videos: