我在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 } }
您可能會發現我給PHPStorm有用的答案,因爲我也一直在爭取讓XDebug工作https://stackoverflow.com/questions/45019201/phpstorm-debug-with-laravel-homestead-not-working/ 45019239#45019239 –