【问题标题】:xdebug failing to go into the laravel appxdebug 无法进入 laravel 应用程序
【发布时间】:2018-07-27 07:30:25
【问题描述】:

我非常喜欢在 laravel 中使用 xdebug(尤其是 vim)。然而最近发生了一些奇怪的事情(注意:当我使用这个命令在单元测试中运行它时,我的 xdebug 工作得很好:

php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 ./vendor/bin/phpunit

  1. 我首先在控制器方法中放置断点,例如
  2. 我在浏览器上运行该命令会触发将调用该控制器方法的 http 调用 断点出现在这里:(project/path/serve.php)

<?php <------- breakpoint appears here

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylorotwell@gmail.com>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

如果我输入命令“获取所有上下文”,我会得到:

$uri                 = /* uninitialized */'';

单步执行转到 if ($uri 行,在这种情况下,uri 会正确显示在 contxt 中

当我跳过该文件的末尾时,它会立即跳到这里:

/**
 * Handle the PHP shutdown event.
 *
 * @return void
 */
public function handleShutdown()
{
    if (! is_null($error = error_get_last()) && $this->isFatal($error['type'])) {

Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()

然后它立即转到raven服务提供者:

/**
 * Register the service provider.
 */
public function register()
{

    ..
    // Register the fatal error handler.
    register_shutdown_function(function () {
        if (isset($this->app['Raven_Client'])) { <---- comes here
            (new Raven_ErrorHandler($this->app['Raven_Client']))->registerShutdownFunction();
        }
    });

Jenssegers\Raven\RavenServiceProvider->Jenssegers\Raven\{closure}()

然后在这里@Raven_Client->onShutdown() /path/to/project/vendor/sentry/sentry/lib/Raven/Client.php:1388

public function onShutdown()
{
    if (!defined('RAVEN_CLIENT_END_REACHED')) { <--
        define('RAVEN_CLIENT_END_REACHED', true);
    }
    $this->sendUnsentErrors();
    if ($this->curl_method == 'async') {
        $this->_curl_handler->join();
    }
}

那么这里@Raven_ErrorHandler->handleFatalError() /path/to/project/vendor/sentry/sentry/lib/Raven/ErrorHandler.php:126

public function handleFatalError()
{
    unset($this->reservedMemory); <---

    if (null === $error = error_get_last()) {
        return;
    }

    if ($this->shouldCaptureFatalError($error['type'])) {
        $e = new ErrorException(
            @$error['message'], 0, @$error['type'],
            @$error['file'], @$error['line']
        );
        $this->handleException($e, true);
    }

那么这里@Monolog\Handler\RotatingFileHandler->__destruct() /path/to/project/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php:169

public function __destruct()
{
    try {
        $this->close();
    } catch (\Exception $e) {
        // do nothing
    } catch (\Throwable $e) {
        // do nothing
    }
}

如何阻止这种情况发生?

更新

我通过这样做从我的环境中删除了 raven 服务提供者:

类 AppServiceProvider 扩展了 ServiceProvider {

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    $env = config('app.env');

    if (!$env === 'local' || !$env === 'testing') {
        $this->app->register(\Jenssegers\Raven\RavenServiceProvider::class);
        $this->app->alias('Raven', Jenssegers\Raven\Facades\Raven::class);
    }

但是现在当我调试时,它仍然在这里:

/**
 * Handle the PHP shutdown event.
 *
 * @return void
 */
public function handleShutdown()
{
    if (! is_null($error = error_get_last()) && $this->isFatal($error['type'])) {

Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()

但它跳过了乌鸦的东西..所以这真的是我的问题。发生了一个错误,但我想在遇到该错误之前进行调试..

更新 2

  • 我注意到中间件中的断点工作正常,但随后它继续跳过我的控制器
  • 如果我从邮递员发出请求(我切换到登录 api 进行烟熏),它工作得很好,这就是我的邮递员命令的样子(转换为 curl):

>

curl --request POST \
  --url 'http://127.0.0.1:8000/api/users/login' \
  --header 'Accept: application/x.toters.v1+json' \
  --header 'Content-Type: application/json' \
  --header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  --form 'email={{client_user_name}}' \
  --form 'password={{general_password}}'

另一方面,这是来自浏览器的请求不起作用:

curl 'http://127.0.0.1:8000/api/users/login'
-X OPTIONS 
-H 'Access-Control-Request-Method: POST' 
-H 'Origin: http://localhost:3000' 
-H 'Accept-Encoding: gzip, deflate, br' 
-H 'Accept-Language: en-US,en;q=0.9' 
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36' 
-H 'Accept: */*' 
-H 'Connection: keep-alive' 
-H 'Access-Control-Request-Headers: content-type' --compressed

【问题讨论】:

  • 如果调试器跳转到任何异常处理程序,是否捕获到任何异常?
  • 我认为它甚至还没有进入该部分..这整个事情发生在完全到达异常部分之前
  • 您是否在用于开发的同一系统上运行网络服务器?在 debian 系统上使用 Apache 并在 vendor 文件夹不包含所有包的 Windows 系统上进行本地开发时,我遇到了类似的问题
  • 都在同一个环境中

标签: php laravel xdebug sentry raven


【解决方案1】:

我最近也遇到了同样的问题,问题是xdebug在执行的第一行就停止了,解决这个问题的关键是

let g:vdebug_options = {'break_on_open': 0}

我所做的修复它被放入.vimrc xdebug 的以下设置中

  let g:vdebug_options = {'ide_key': 'vim-xdebug'}
  let g:vdebug_options = {'break_on_open': 0}
  let g:vdebug_options = {'server': '127.0.0.1'}
  let g:vdebug_options = {'port': '10000'}
  let g:vdebug_options["path_maps"] = {
  \ "/project": "<project-path>"
  \}

我还安装了这个 chrome 扩展程序 Xdebug helper,它现在可以正常工作了。

如果你想咨询,这些是我的 xdebug 设置

xdebug.ini:

zend_extension=xdebug.so

[debug]
; Remote settings
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=10000

; General
xdebug.auto_trace=off
xdebug.collect_includes=off
xdebug.collect_params=off
xdebug.collect_return=off
xdebug.default_enable=off
xdebug.extended_info=1
xdebug.manual_url=http://www.php.net
xdebug.show_local_vars=0
xdebug.show_mem_delta=0
xdebug.max_nesting_level=500
xdebug.idekey=vim-xdebug

; Trace options
xdebug.trace_format=0
xdebug.trace_output_dir=/tmp
xdebug.trace_options=0
xdebug.trace_output_name=crc32

; Profiling
xdebug.profiler_append=0
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=0
xdebug.profiler_output_dir=/tmp
xdebug.profiler_output_name=crc32

php.ini

xdebug.remote_connect_back=1
xdebug.remote_port = 9000
xdebug.remote_autostart = 1

【讨论】:

  • 我不认为这回答了这个问题,我不认为在第一行突破是 @abbood 的情况。
猜你喜欢
  • 2018-12-24
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 1970-01-01
  • 2019-05-08
  • 1970-01-01
  • 1970-01-01
  • 2017-02-04
相关资源
最近更新 更多