Visual Studio Code Xdebug

0 views
Skip to first unread message
Message has been deleted

Mirthe Luria

unread,
Jul 12, 2024, 9:42:39 PM7/12/24
to dazzwirkgrowag

Manage pull requests and conduct code reviews in your IDE with full source-tree context. Comment on any line, not just the diffs. Use jump-to-definition, your favorite keybindings, and code intelligence with more of your workflow.
Learn More

visual studio code xdebug


DESCARGAR https://urllio.com/2yPlMr



Install XdebugI highly recommend you make a simple test.php file, put a phpinfo(); statement in there, then copy the output and paste it into the Xdebug installation wizard. It will analyze it and give you tailored installation instructions for your environment. In short:

There are other ways to tell Xdebug to connect to a remote debugger, like cookies, query parameters or browser extensions. I recommend remote_autostart (Xdebug v2)/start_with_request (Xdebug v3) because it "just works". There are also a variety of other options, like the port, please see the Xdebug documentation on remote debugging for more information. Please note that the default Xdebug port changed between Xdebug v2 to v3 from 9000 to 9003.

Note: You can even debug a script without launch.json. If no folder is open, and the VS Code status bar is purple, pressing F5 will start the open script with Xdebug3 specific parameters. If the php executable is not in path, you can provide it with the setting php.debug.executablePath. For debugging to work, Xdebug must still be correctly installed.

To debug a running application on a remote host, you need to tell Xdebug to connect to a different IP than localhost. This can either be done by setting xdebug.client_host to your IP or by setting xdebug.discover_client_host = 1 to make Xdebug always connect back to the machine who did the web request. The latter is the only setting that supports multiple users debugging the same server and "just works" for web projects. Again, please see the Xdebug documentation on the subject for more information.

Please also note that setting any of the CLI debugging options will not work with remote host debugging, because the script is always launched locally. If you want to debug a CLI script on a remote host, you need to launch it manually from the command line.

The debugger can register itself to a DBGp proxy with a IDE Key. The proxy will then forward to the IDE only those DBGp sessions that have this specified IDE key. This is helpful in a multiuser environment where developers cannot use the same DBGp port at the same time. Careful setup is needed that requests to the web server contain the matching IDE key.

Tests are written with Mocha and can be run with npm test or from Terminal / Run Task... / npm: test. When you submit a PR the tests will be run in CI on Linux, macOS and Windows against multiple PHP and Xdebug versions.

Next, in the terminal, install $ pecl install xdebug. This is going to kick off a process that will install Xdebug and set up the module in PHP. At this point, running $ php -v should show that Xdebug is installed.

Return to Visual Studio Code, click on Run and Debug then, in the top of the panel, choose Listen for Xdebug and click the Play icon. This will bring up the set of controls for stopping, pausing, starting, stepping over, and stepping into code.

Find a line in your code that you know will fire and click next to it in the IDE. This will set a breakpoint. Optionally, select a variable that will be set at some point during execution, highlight it, and choose Add to Watch.

Kinsta offers premium managed WordPress hosting for everyone, small or large. Powered by Google Platform and strengthened by Cloudflare, they take performance to the next level. All hosting plans include 24/7/365 support from their team of WordPress engineers. Get started with a free migration today.

Just Getting Started with WordPress? I write a lot about WordPress development but if you're just getting started, I recommend checking out WPBeginner. They have free training videos, glossary, and more.

I have a progress with this case, I mean, still xdebug is not working on my Devilbox v1.9.2 (2021-06-04) (was easy on Lando but I want to have running on Devilbox). According my findings, the problem could be related that Devilbox that I am using comes with Xdebug 3, and the documentation is in some places outdated regarding that.

First I follow the Linkedin source instructions, unfortunately was not working for me, so I have added the service:php: port portion described at the github source for devilbox\docker-compose.override.yml file described at github resource.

Now I have the issue related with port conflict, I think that is a good progress. In my case the address that gives a connection (I mean, it works! (did it?) but with the conflict) is docker.for.lin.host.internal. That docker.for.lin.host.internal can be found in .env.

I tried this in my xdebug.ini on devilbox, and its working!! Typing xdebug. does not show me this option, maybe a mistake in intellisense or whatever is there in the background? Thats why I did not try this before.

Hello Ernestopheles, thanks for your comments and ideas, give me the push forward to follow.
I removed xdebug.ini custom changes added to cfg / php-ini-7.4 directory in devilbox, then stop / run again devilbox and according php info xdebug is using address 172.16.238.1 (maybe xdebug was affected with starting changes to the configuration, anyway , the expected address appears). Then I enabled xdebug on VSCode again but this time using the common 9000 (and not the 9003 expected by new xdebug version), and the orange bar related to connection made showed up now on VScode !!.

not sure if i can follow your description. But I solved the problem for me, you will find the configuration for linux, xdebug 3 and vscode here: Update vscode.rst by Ernestopheles Pull Request #836 cytopia/devilbox GitHub

This protocol is supported by nearly every PHP IDE (including Visual Studio Code and PhpStorm), and also by text-based editors. There isalso a simple Command Line Debug Client available as part of the Xdebug project,but it is strongly recommended that you use an IDE for debugging. (An overview of third party clients is available further downthis page.)

In your php.ini, 99-xdebug.ini, or otherdistribution specific PHP ini file, change (or set) the xdebug.mode setting todebug. Please refer to Configure PHP in the documentation tofind out which PHP ini file to modify.

If PHP/Xdebug run on a different machine, virtual host, or in a Dockercontainer, you need to tell Xdebug where to make the debugging connectionto, as it is Xdebug that initiates the communication to the IDE, and notthe other way around.

If PHP/Xdebug run on a different machine in the same sub-net, and you runyour browser on the same host as your IDE, then you set thexdebug.discover_client_host setting to 1. Xdebug will then use theHTTP headers to find out the IP address of the host that initiated thedebugging request, and use that IP address to connect to. This is a commonway of set-up if you are sharing a development server among you and your teammates.

In more complex set-ups you need to configure the host and port that Xdebugconnects to yourself. With xdebug.client_host you can select the IP or hostnameof the machine that runs your IDE, and with xdebug.client_port the TCP port.Make sure that the host running PHP/Xdebug can connect to your IDE with theconfigured IP address and port, and that there is no firewall or other softwareblocking an incoming connection.

In the default configuration, the debugger activates if a "trigger" ispresent, although it's possible to instruct the debugger to always initiate adebugging session by setting xdebug.start_with_request to yes.

Each extension adds an icon to your browser where you can select whichfunctionality you want to trigger. Xdebug will continue to start debugging forevery request as long as the debug toggle has been enabled.

Alternatively, you can signal Xdebug to initiate debugging for asingle request by addingXDEBUG_SESSION=session_name as additional GET (orPOST) parameter. You can pick any value forsession_name, unless xdebug.trigger_value is set.

Xdebug will initiate a debug session in the presence of theXDEBUG_SESSION HTTP cookie. You can pick any value for the cookie,unless xdebug.trigger_value is set, in which case the value needs to match thevalue/one of the values from xdebug.trigger_value.

Calling xdebug_break() will trigger a debugging connection as long asxdebug.start_with_request is set to trigger and no debugger sessionis active yet. If a debugger session is already active, it will simply act asif a breakpoint was set through your IDE.

You can troubleshoot Xdebug's attempts at initiating debugging connectionsby configuring a log file through xdebug.log. When the connection issuccessfully established the log will also contain the communication betweenXdebug and IDE.

The log file will contain to which IP addresses it is attempting to connectand at which ports, which should be a great help debugging why it sometimesdoesn't work. A "remote log file" is also required when reporting a bug inXdebug's step debugger.

Xdebug's implementation of theDBGp protocol's context_namescommand does not depend on the stack level. The returned value is always thesame during each debugger session, and hence, can be safely cached.

This command returns which lines in an active stack frame can have a workingbreakpoint. These are the lines which have an EXT_STMTopcode on them. This commands accepts a -d option, whichindicates the stack depth, with 0 being the top leve stack frame.

If xdebug.client_discovery_header is configured to be a non-empty string, then thevalue is used as key in the $_SERVER superglobal array to determinewhich header to use to find the IP address or hostname to use for 'connectingback to'. This setting is only used in combination withxdebug.discover_client_host and is otherwise ignored.

It is possible to configure multiple fallbacks by using a comma separatedlist of values. For example if you want to use HTTP_FORWARD_HOSTfirst, and then also want to check REMOTE_ADDR, then you setxdebug.client_discovery_header toHTTP_FORWARD_HOST,REMOTE_ADDR.

d3342ee215
Reply all
Reply to author
Forward
0 new messages