Laravel 5 Xdebug 总是抛出 "The payload is invalid."

Laravel 5 with Xdebug always throws "The payload is invalid."

我在 VScode 上配置了 Xdebug 来调试我的 laravel 应用程序。但是,当我开始调试时,laravel 总是抛出这个错误:Exception has occurred. Illuminate\Contracts\Encryption\DecryptException: The payload is invalid.

我已经试过了 运行 php artisan optimize.

这里有人遇到过这个问题吗?我正在使用 Laravel 5.5

Ps。我试图调试 Laravel 4 应用程序。它没有任何问题。所以,我认为这可能是 Laravel 5.

的特定内容

@ceejayoz 的评论解决了这个问题。我 运行 php artisan 优化,并清除浏览器上的所有 cookie,它开始正常工作。

就我而言,我还必须关闭 ExceptionsEverything 的报告,否则,问题仍然存在。

默认情况下 Laravel 将加密并随后解密请求中的所有 cookie。

当使用 Xdebug 从浏览器调试您的应用程序时,会设置一个名为 "XDEBUG_SESSION" 的 cookie。由于此 cookie 未设置,因此未被 Laravel 框架加密,当框架自动检测并尝试解密 cookie 时将抛出错误。

正确的解决方案是将 "XDEBUG_SESSION" cookie 添加到 App\Http\Middleware\EncryptCookies 中间件的异常数组中。

/**
 * The names of the cookies that should not be encrypted.
 *
 * @var array
 */
protected $except = [
    'XDEBUG_SESSION'
];

这是我的解决方案。我正在使用 VsCode 并且文件配置 xdebug (launch.json) 必须与工作区

匹配
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "log":true,
        "pathMappings": {

           // "serverSourceRoot": "/var/www/html",
            //"localSourceRoot": "${workspaceRoot}"
            "/var/www/html":"/Users/{username}/sites/{mysitefolder}"

        },
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000
    }
]

}

临时注释掉\App\Http\Middleware\EncryptCookies::class,它在app/Http/Kernel的web中间件组里面。解决了我的问题。不过需要记住把它转回去。任何人有更好的解决方案吗?我试过上面提到的方法,不幸的是没有人为我工作。

如果答案无效,请尝试将其添加到 launch.json

{
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9001,
        "ignore": [
            "**/vendor/**/*.php"
        ]
    },

更多信息