0

My php-debugging with xdebug in visual studio only works sometimes. Some of the times i just get a normal browser page load (error log below).

Edit: At first i thought it was due to the location of the file, but I noticed it could happen in any location; either xdebug finds an error in the code without stopping at my own breakpoints; or it can find all types of breakpoints OR find nothing at all... Now I'm thinking it has to do with refreshing, modifying and resaving the file as well as what types of errors are in the file. I'll get back to this if I can find out what causes it.

In my current setup I have my localhost webroot at /home/user/Git/www/projects which is where 127.0.0.1 points to. However, I've also set up multiple virtual hosts that reside in their respective subfolders: /home/user/Git/www/projects/project_name.


Some things I already looked at

In this thread: Visual Studio Code - Xdebug won't work - They suggest setting xdebug.remote_connect_back = 1, which doesn't solve the problem. They also suggest setting localSourceRoot in launch.json to point to server root. However, simply adding "localSourceRoot": "http://127.0.0.1" or something like "localSourceRoot": "http://127.0.0.1/project_name" did not work.


Logs

/etc/hosts

127.0.0.1   project_names
127.0.0.1   php
127.0.0.1   localhost 
::1         localhost

php.ini:

[Xdebug] 
zend_extension = xdebug.so
xdebug.remote_enable = on
xdebug.remote_autostart = on
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9000
xdebug.remote_mode = req
xdebug.idekey=php-vs
;xdebug.remote_connect_back = 1

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "log": true,
            "request": "launch",
            "port": 9000
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

VS Debug Console:

<- launchResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 2,
  command: 'launch',
  success: true }

new connection 1
<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'started', threadId: 1 } }

<- initializedEvent
InitializedEvent { seq: 0, type: 'event', event: 'initialized' }

-> threadsRequest
{ command: 'threads', type: 'request', seq: 3 }

<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 3,
  command: 'threads',
  success: true,
  body: { threads: [ Thread { id: 1, name: 'Request 1 (9:06:23 PM)' } ] } }

-> setBreakpointsRequest
{ command: 'setBreakpoints',
  arguments: 
   { source: 
      { path: '/home/micke/Git/www/projects/php/trial.php',
        name: 'trial.php' },
     lines: [ 14 ],
     breakpoints: [ { line: 14 } ],
     sourceModified: false },
  type: 'request',
  seq: 4 }

<- setBreakpointsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 4,
  command: 'setBreakpoints',
  success: true,
  body: { breakpoints: [ { verified: true, line: 14 } ] } }

-> setFunctionBreakpointsRequest
{ command: 'setFunctionBreakpoints',
  arguments: { breakpoints: [] },
  type: 'request',
  seq: 5 }

<- setFunctionBreakpointsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 5,
  command: 'setFunctionBreakpoints',
  success: true,
  body: { breakpoints: [] } }

-> setExceptionBreakpointsRequest
{ command: 'setExceptionBreakpoints',
  arguments: { filters: [ '*' ] },
  type: 'request',
  seq: 6 }

<- setExceptionBreakpointsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 6,
  command: 'setExceptionBreakpoints',
  success: true }

-> configurationDoneRequest
{ command: 'configurationDone', type: 'request', seq: 7 }

-> threadsRequest
{ command: 'threads', type: 'request', seq: 8 }

<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 8,
  command: 'threads',
  success: true,
  body: { threads: [ Thread { id: 1, name: 'Request 1 (9:06:23 PM)' } ] } }

<- configurationDoneResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 7,
  command: 'configurationDone',
  success: true }

<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'exited', threadId: 1 } }
Cutgah
  • 11
  • 4
  • You might find the answer I gave for PHPStorm usefull as I too have been wrestling with getting XDebug to work https://stackoverflow.com/questions/45019201/phpstorm-debug-with-laravel-homestead-not-working/45019239#45019239 – online Thomas Sep 01 '17 at 09:22

3 Answers3

0

I finally realized that the problem was related to mountpoints. The project in VScode was opened on the path where the webserver was mounted; not where it was originally pointing to in apache. So the breakpoints were considered added to another file as the path was not the same.

Cutgah
  • 11
  • 4
  • Can you share how you managed to fix that? I have here 2 local projects, one of them xdebug works perfectly, the other doesn't – Matheus May 09 '18 at 13:02
  • Was some time ago now, but I think i just opened VScode in the original web path as specified in apache, instead of opening it indirectly in a some mounted or mb symlinked path. – Cutgah May 10 '18 at 19:06
0

your debug works sometimes, it seems your config is right, so the reason might caused by the port of php xdebug. It works for me fine when I did this:

1.use php --ini to show php config file and change xdebug port to 9900(or other number): xdebug.remote_port=9900 then restart your php

2.change the vscode xdebug port to the same number in launch.json: "port": 9900

3.enjoy your debug

lecover
  • 62
  • 4
0

update to last version of xdebug and set xdebug.remote_timeout to higher value like 3000