0

I read and followed "How to set up VSCode, PHP Debug and XDebug (Windows 10)", and I got to stop at breakpoints and apparently debug my PHP script.

However, I want to interact with the browser, and this doesn't occur. I would like my debug process to wait for launching my web browser and then see the effect in it.

Before moving to my new PC (now I have Windows 11) I could select "Listen for debug", and then over my web browser I typed "localhost" and I was able to see the effect of my script, and also the script could respond to buttons if I pressed them. However, it seems that now, there is no connection to the web browser.

I have also tried selecting "Launch built-in web server" (instead "Listen for Debug" or "Launch currently open script") In this case, the web browser started but the debugger did not stop at the breakpoints, so it was like not debugging.

I opened netstat and port 9000 is occupied by Code.exe when I press "Listen for XDebug", but not when I press "Launch built-in web server".

Any help will be appreciated.

Sorry for not replying sooner. I didn't see any notification. I included the extension PHP Debug v1.32.1 (Debug support for PHP with XDebug). PHP 8.2.4.0

What I have in launch.json is (I have already changed the port to 9003 everywhere)

{    
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
        
        { // port was previously as 0
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}

xdebug_info() provides the following

Version 3.2.1
Support Xdebug on Patreon, GitHub, or as a business
Enabled Features
(through 'xdebug.mode' setting)
Feature Enabled/Disabled    Docs
Development Helpers ✔ enabled   ⊕
Coverage    ✘ disabled  ⊕
GC Stats    ✘ disabled  ⊕
Profiler    ✘ disabled  ⊕
Step Debugger   ✘ disabled  ⊕
Tracing ✘ disabled  ⊕
Optional Features
Compressed File Support yes (gzip)
Clock Source    GetSystemTimePreciseAsFileTime
'xdebug://gateway' pseudo-host support  no
'xdebug://nameserver' pseudo-host support   no
Systemd Private Temp Directory  not enabled
Diagnostic Log
No messages
PHP
Build Configuration
Version (Run Time)  8.2.4
Version (Compile Time)  8.2.4
Debug Build no
Thread Safety   enabled
Thread API  Windows Threads
Settings
Configuration File (php.ini) Path   no value
Loaded Configuration File   C:\xampp\php\php.ini
Scan this dir for additional .ini files (none)
Additional .ini files parsed    (none)
Directive   Local Value Master Value    Docs
xdebug.cli_color    0   0   ⊕
xdebug.client_discovery_header  HTTP_X_FORWARDED_FOR,REMOTE_ADDR    HTTP_X_FORWARDED_FOR,REMOTE_ADDR    ⊕
xdebug.client_host  localhost   localhost   ⊕
xdebug.client_port  9003    9003    ⊕
xdebug.cloud_id no value    no value    ⊕
xdebug.collect_assignments  Off Off ⊕
xdebug.collect_return   Off Off ⊕
xdebug.connect_timeout_ms   200 200 ⊕
xdebug.discover_client_host Off Off ⊕
xdebug.dump.COOKIE  no value    no value    ⊕
xdebug.dump.ENV no value    no value    ⊕
xdebug.dump.FILES   no value    no value    ⊕
xdebug.dump.GET no value    no value    ⊕
xdebug.dump.POST    no value    no value    ⊕
xdebug.dump.REQUEST no value    no value    ⊕
xdebug.dump.SERVER  no value    no value    ⊕
xdebug.dump.SESSION no value    no value    ⊕
xdebug.dump_globals On  On  ⊕
xdebug.dump_once    On  On  ⊕
xdebug.dump_undefined   Off Off ⊕
xdebug.file_link_format no value    no value    ⊕
xdebug.filename_format  no value    no value    ⊕
xdebug.force_display_errors Off Off ⊕
xdebug.force_error_reporting    0   0   ⊕
xdebug.gc_stats_output_name gcstats.%p  gcstats.%p  ⊕
xdebug.halt_level   0   0   ⊕
xdebug.idekey   VSCODE  VSCODE  ⊕
xdebug.log  no value    no value    ⊕
xdebug.log_level    7   7   ⊕
xdebug.max_nesting_level    256 256 ⊕
xdebug.max_stack_frames -1  -1  ⊕
xdebug.mode develop develop ⊕
xdebug.output_dir   C:\Windows\Temp C:\Windows\Temp ⊕
xdebug.profiler_append  Off Off ⊕
xdebug.profiler_output_name cachegrind.out.%p   cachegrind.out.%p   ⊕
xdebug.remote_autostart (setting renamed in Xdebug 3)   (setting renamed in Xdebug 3)   ⊕
xdebug.remote_enable    (setting renamed in Xdebug 3)   (setting renamed in Xdebug 3)   ⊕
xdebug.remote_host  (setting renamed in Xdebug 3)   (setting renamed in Xdebug 3)   ⊕
xdebug.remote_mode  (setting renamed in Xdebug 3)   (setting renamed in Xdebug 3)   ⊕
xdebug.remote_port  (setting renamed in Xdebug 3)   (setting renamed in Xdebug 3)   ⊕
xdebug.scream   Off Off ⊕
xdebug.show_error_trace Off Off ⊕
xdebug.show_exception_trace Off Off ⊕
xdebug.show_local_vars  Off Off ⊕
xdebug.start_upon_error default default ⊕
xdebug.start_with_request   default default ⊕
xdebug.trace_format 0   0   ⊕
xdebug.trace_options    0   0   ⊕
xdebug.trace_output_name    trace.%c    trace.%c    ⊕
xdebug.trigger_value    no value    no value    ⊕
xdebug.use_compression  1   1   ⊕
xdebug.var_display_max_children 128 128 ⊕
xdebug.var_display_max_data 512 512 ⊕
xdebug.var_display_max_depth    3   3   ⊕

In php.ini, I have (part of it)

[Zend Modules]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9003

[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9003
xdebug.idekey=VSCODE
[Syslog]

The dll file was the one suggested and later renamed.

I have used XAMPP, and I can see Apache and MySql in green, so I think there is not conflict with some other application.

When I type localhost/debug in my web browser (Chrome or Edge), I can see the icon of Xampp.

To summarize:

  • if I press Listen for Debug, then it does not debug (do not stop at breakpoints) and the web page is loaded as if not running VS.
  • if I press Launch currently open script, then it debugs (stops at breakpoints), but the web page in localhost/debug does not seem to interact with the VS.
  • *"I opened netstat and port 9000 is occupied by Code.exe when I press "Listen for XDebug", but not when I press "Launch built-in web server"."* Well, that means that you have to show your launch configs. Otherwise how to know what you have got there? Showing your actual/live Xdebug config will also be useful. What PHP/Xdebug version have you got there BTW? – LazyOne Apr 08 '23 at 09:02
  • Sorry for not replying sooner. I didn't see any notification. Please see launch.json as additional notes in the modified question above. I included the extension PHP Debug v1.32.1 (Debug support for PHP with XDebug). PHP 8.2.4.0 – Angel Gaspar Apr 12 '23 at 22:16
  • Please post your Xdebug config. What you have in `php.ini` as well as the output of `xdebug_info();` captured in the same way as yu are trying to debug (a web page). I've tried your `Launch Built-in web server` config on my Windows 10 (copy+pasted it) and it worked just fine -- VSCode listens on Xdebug port. The only thing I've changed is Xdebug port (as I'm using the default one). **BTW** -- why using `9000` when you are using Xdebug v3? v3 uses `9003` by default. So it makes sense to use it as well. – LazyOne Apr 12 '23 at 23:04
  • Thank you very much. Now it works. I have changed 9000->9003 everywhere (php.ini and launch.json) and used "Launch Built-in web server". Previously I mainly focused on "Listen for Debug" and "Launch currently open script", and it did not work, but with "Launch Built-in web server" is OK. Thank you for your time and expertise – Angel Gaspar Apr 13 '23 at 00:45
  • You have Xdebug v3 but you are using config parameters for v2. They do almost nothing in v3. Go though the upgrade guide and upgrade your php.ini config: https://xdebug.org/docs/upgrade_guide . On related note: https://stackoverflow.com/a/65141934/783119 **P.S.** There is no need to list Xdebug params 2 times under different section names. Only 1 should be used. – LazyOne Apr 13 '23 at 00:46
  • Now, I know ;) This is a platform which I am not familiar with, and I have many gaps. Thanks again – Angel Gaspar Apr 13 '23 at 00:52

0 Answers0