代码之家  ›  专栏  ›  技术社区  ›  Cutgah

在visual studio代码中进行PHP调试有时只起作用

  •  0
  • Cutgah  · 技术社区  · 7 年前

    我在visual studio中使用xdebug进行的php调试有时才有效。有时我只是得到一个正常的浏览器页面加载(错误日志如下)。

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

    /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 "localSourceRoot": "http://127.0.0.1" 或者类似的 "localSourceRoot": "http://127.0.0.1/project_name" 不起作用。


    /etc/主机

    127.0.0.1   project_names
    127.0.0.1   php
    127.0.0.1   localhost 
    ::1         localhost
    

    [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
    

    {
        "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 } }
    
    3 回复  |  直到 7 年前
        1
  •  0
  •   Cutgah    7 年前

    安装 ; 而不是它最初在apache中指向的位置。因此,断点被视为添加到另一个文件中,因为路径不同。

        2
  •  0
  •   lecover    6 年前

    您的调试有时会工作,似乎您的配置是正确的,因此原因可能是由php xdebug的端口引起的。当我这样做的时候,它对我来说很好:

    1.使用 php --ini 要显示php配置文件并将xdebug端口更改为9900(或其他数字): xdebug.remote_port=9900 然后重新启动php

    "port": 9900

        3
  •  0
  •   AlejandroAlis    5 年前

    更新至xdebug的最新版本并设置 到更高的值,如3000