PHP 8 & Xdebug .....


  • | 1735 points

    PHP 8

    New to Laragon, and can't get Xdebug to work although it is a fresh install for both.

    PHP 8 has been downloaded here

    This is the error when trying to load Xdebug.
    0_1627654128976_upload-5e01cdb7-88fa-40e2-b16f-3b326e8ca9d9

    The PHP.ini file gives the right location
    0_1627654240888_upload-b9274f22-e7a0-4bb0-9046-0c8f12edd664

    Not sure where the settings are wrong......


  • | 16270 points

    @DickVG I've written a blog which has a section for Xdebug: Standard setup for PHP projects 2021/#Xdebug, I hope this information helps.


  • | 16270 points

    @DickVG I've just noticed you are trying to load the non-thread safe (NTS) version of Xdebug in a thread-safe (TS) version of PHP.

    PHP has 4 versions available to download, 32-bit or 64 bit, Thread Safe (TS) or Non Thread Safe (NTS). For Laragon v5 you would use 64 bit. Apache requires the Thread Safe (TS) version, Internet Information Services (IIS) requires the Non-Thread Safe version (NTS). The version of Xdebug needs to match the version of PHP, so in your case, you would need Xdebug for PHP 8, 64 bit, TS

    0_1627668673800_upload-30d0b6c0-7dbe-4a7c-8645-fa12808ee151

    You can then add this dll file to the PHP ext directory and include in php.ini:

    zend_extension=php_xdebug-3.0.4-8.0-vs16-x86_64.dll
    
    ; develop can be used always:
    xdebug.mode = develop
    ; enable debug and code coverage when required:
    ; xdebug.mode = coverage,debug,develop
    
    xdebug.client_host=localhost
    xdebug.client_port = 9003
    xdebug.start_with_request = yes
    

  • | 1735 points

    @Pen-y-Fan It's always in a small detail... I should have seen it. Thanks a lot.

    It seems to be loaded:
    0_1627736980531_upload-6bad322c-edd7-4da7-a6a3-8f97de129f23

    It does not show in the menu, and you can not click to load or unload like other extensions.
    0_1627737106576_upload-a80663f5-44cb-4ae0-8bcd-d999c2144d61

    Although I see this in Quick Settings:
    0_1627737172842_upload-c3a98df6-912f-4430-99cc-562a2b0ec2ac

    Not sure if this is right.


  • | 16270 points

    @DickVG yes, that looks like it's working, check your php.ini to see if there are two lines for Xdebug, maybe one is commented out. You can also click the Web button and you will see a Laragon information page, click info next to the PHP version and you will see phpinfo(), this will also confirm the modules loaded, Xdebug is about halfway down the page.

    0_1627742503240_upload-3d69a55a-e9f7-41ca-8576-dbeee93875a7


  • | 1735 points

    @Pen-y-Fan: Thanks for your help. I have exactly the same information on my phpinfo().

    Still no Breakpoints and debugging does not happen. I don't see variables or other information when running the debugger

    0_1627745775329_upload-189d7c6b-15dd-4141-b1b0-57749eae5963

    Any advice?


  • | 1735 points

    @Pen-y-Fan

    I added a log file. These are my ini settings:

    0_1627746038287_upload-c559a51c-d9b3-4180-b65f-e97a94519c98

    The problem apparently is mentioned in the log:

    [9560] [Step Debug] WARN: 1970-01-01 00:41:28.989970: There was a problem sending 179 bytes on socket 1264: An existing connection was forcibly closed by the remote host.


  • | 16270 points

    @DickVG

    I'm using PhpStorm. I haven't used vs code in a while, so I opened it up.

    See this blog for instructions: Tutorial: Using Xdebugger with PHP & VSCode to Debug

    After installing the Xdebug extension for VS Code

    0_1627761542833_upload-a8f9c949-423b-408c-85aa-be87868e9d43

    I set up php.ini:

    zend_extension=xdebug-3.0.4-8.0-vs16-x86_64
    
    xdebug.mode = debug
    
    xdebug.client_host=localhost
    xdebug.client_port = 9003
    xdebug.start_with_request = yes
    

    Then saved the configuration file (click the cog icon) - this was auto-generated:

    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            
            {
                "name": "Listen for Xdebug",
                "type": "php",
                "request": "launch",
                "port": 9003
            },
            {
                "name": "Launch currently open script",
                "type": "php",
                "request": "launch",
                "program": "${file}",
                "cwd": "${fileDirname}",
                "port": 0,
                "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"
                }
            }
        ]
    }
    

    I created a simple example.php script

    <?php 
    $message = "Hello, world";
    echo $message;
    

    Set debug on the echo line and ran the script with debug.

    0_1627761899799_upload-13c37554-f62e-4b0a-a2a4-f87732be5f6b

    I hope this helps.


  • | 16270 points

    @DickVG for web requests I used the Xdebug helper extension

    Opened the webpage, in my case http://xdebug-test.local/example.php

    Then enabled the Xdebug extension to debug and set VS Code to listen for Xdebug, refreshed the page and it stopped at the breakpoint:

    0_1627765087699_upload-b7d27b31-94ad-457d-b35e-a125f3e7429a

    1. Set Xdebug extension to Debug
    2. Set VS Code to listen for Xdebug
    3. Set the breakpoint
    4. Refresh the page and view with to VS Code
    5. Note: "Hello, world" was already displayed on the webpage you can see when I refreshed the page the loading icon is "going around", while I was debugging. I had to switch to VS Code (Ctrl + Tab), it didn't automatically focus, although it had detected the Xdebug breakpoint. You can see the local variable is set. Press F8 to step over.

  • | 1735 points

    I still can't get it to work. I think the problem is, that only Xdebug appears in the Quick Settings, but activating the setting will not work, although Apache is reloading. All other extensions can be unloaded and loaded from the menu. Xdebug is added from within Visual Studio as an extension

    0_1627813788550_upload-3f85fcbc-03ed-4e7f-ac28-4b283a940faf


  • | 1735 points

    Digging somewhat further I read that the command xdebug_break() should stop at the next line in your PHP code.

    0_1627815031453_upload-4b1f2828-0ef3-4401-9eee-25377ed739c4

    But it shows this error while refreshing the Browser page:
    Fatal error: Uncaught Error: Call to undefined function xdebug_break()

    My guess is that although Xdebug is added in Visual Studio as an extension, for some reason it will not load with Laragon and causes those problems.


  • | 16270 points

    @DickVG example of xdebug_break() working:

    0_1627815952797_upload-f0382fa2-ef0f-49a8-8aeb-9dc29ca45e41

    My guess is Xdebug hasn't loaded, check your php.ini has Xdebug loaded and debug is enabled:

    zend_extension=xdebug-3.0.4-8.0-vs16-x86_64
    xdebug.mode = coverage,debug,develop
    
    <?php 
    $message = "<h1>Hello, world</h1>";
    $xdebugBreak = xdebug_break();
    echo $message;
    ?>
    

    If you have changed PHP version stop and start Laragon, then check the info.

    0_1627816311755_upload-aff75ee0-79d4-4fbb-873a-e797a495d428


  • | 1735 points

    @Pen-y-Fan I have the same output in the info for Xdebug.

    It might be a problem with the port 9003 (which is also used for MSQL?)

    phi.ini is
    0_1627819059192_upload-d2e38283-6f3e-471a-b5e4-541a23e72742

    This is the error log.

    [18444] [Step Debug] INFO: Connecting to configured address/port: 127.0.0.1:9003.
    [18444] [Step Debug] INFO: Connected to debugging client: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port). :-)
    [18444] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///C:/Laragon/www/Test/home.php" language="PHP" xdebug:language_version="8.0.4RC1" protocol_version="1.0" appid="18444" idekey="VSCODE"><engine version="3.0.4"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2021 by Derick Rethans]]></copyright></init>

    [18444] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="break" reason="ok"><xdebug:message filename="file:///C:/Laragon/www/Test/home.php" lineno="4"></xdebug:message></response>

    [18444] [Step Debug] WARN: 2021-08-01 11:53:43.800208: There was a problem sending 268 bytes on socket 1224: An existing connection was forcibly closed by the remote host.
    [18444] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

    [18444] [Step Debug] WARN: 2021-08-01 11:53:43.800401: There was a problem sending 179 bytes on socket 1224: An existing connection was forcibly closed by the remote host.
    [18444] Log closed at 2021-08-01 11:53:43.800478


  • | 16270 points

    @DickVG you can only have one app listening on port 9003, if you have other VS Code tabs open close all debug listeners (click the stop icon)

    0_1627821762561_upload-4bb7bbdc-3dd6-4448-8123-3fc372f00659

    You can run netstat (Menu > Tools > netstat) and see if Code, or another app, is listening on port 9003

    0_1627821915143_upload-c09118fe-2e08-4283-836e-f745b1f99579

    You should only see this line when Code is set to listen for Xdebug.

    Try xdebug.client_host=localhost (comment out the line with 127.0.0.1)

    MySQL listens on port 3306. Sometimes I've seen problems with port 9000, which I why I expect it was changed to 9003, if another app is using 9003 either close the other app or change the client_port in php.ini and VS Code config.


  • | 1735 points

    @Pen-y-Fan

    I'm learning a lot thanks to you, but the problem is still not solved.

    I'm on a Windows 10 machine and Netstat does not show Path in Windows apparently, so I looked up the PID and it confirms the CODE.exe for Visual Code.

    0_1627830776730_upload-510f5d6f-9038-4bf5-9528-4ee82d3ce5ec

    0_1627830869023_upload-c7379411-489d-40a3-ad2e-58c74653cda5

    I'm still searching to make it work. Any other suggestions?


  • | 1735 points

    Wait...

    I checked the other port for MSQL and APACHE and if NA means Not Available that could be the reason.

    0_1627831140771_upload-e2dc3dba-a0de-4b63-aeb9-3da629c3d46f


  • | 1735 points

    I finally made it work....

    The extension Intelephense interferes with Xdebug apparently. When deactivating Intelephense everything works fine.

    Again thanks for your time and guidance. I learned a lot and you made me search on a lot of information that will be useful for the future.

    0_1627850816875_upload-9776d911-40b3-4ed4-a1ec-798857e3dcf6


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.