在Visual Studio代码中进行PHP调试仅适用于有时

问题描述:

我在Visual Studio中使用xdebug进行的php调试仅在有时会起作用。有些时候,我只是得到一个正常的浏览器页面加载(错误日志下面)。在Visual Studio代码中进行PHP调试仅适用于有时

编辑: 起初我以为这是由于文件的位置,但我注意到它可能发生在任何位置;或者xdebug在代码中发现一个错误而不会停留在我自己的断点处;或者它可以找到所有类型的断点或根本找不到任何东西......现在我认为它与刷新,修改和重新保存文件以及文件中的错误类型有关。如果我能找出是什么原因,我会回头看看。

在我目前的设置中,我有我的localhost webroot在/home/user/Git/www/projects这是127.0.0.1指向的地方。但是,我还设置了多个驻留在各自子文件夹中的虚拟主机:/home/user/Git/www/projects/project_name


有些事情我已经看了

在这个线程:Visual Studio Code - Xdebug won't work - 他们建议设置xdebug.remote_connect_back = 1,不解决问题。他们还建议在launch.json中将localSourceRoot设置为指向服务器根目录。但是,只需添加"localSourceRoot": "http://127.0.0.1"或诸如"localSourceRoot": "http://127.0.0.1/project_name"之类的东西都不起作用。


日志

/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调试控制台:

<- 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 } } 
+0

您可能会发现我给PHPStorm有用的答案,因为我也一直在争取让XDebug工作https://*.com/questions/45019201/phpstorm-debug-with-laravel-homestead-not-working/ 45019239#45019239 –

我终于意识到,这个问题是关系到挂载点。 VScode中的项目在网络服务器安装的路径上打开;而不是它最初指向apache的地方。所以断点被认为是添加到另一个文件,因为路径不一样。