L5随机TokenMismatchExceptions [英] L5 random TokenMismatchExceptions

查看:86
本文介绍了L5随机TokenMismatchExceptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel 5中得到了随机的TokenMismatchExceptions.在tokensMatch()函数中使用以下代码,我一直在尝试调试这个奇怪的问题:

I'm getting random TokenMismatchExceptions in Laravel 5. Using the following code in the tokensMatch() function I've been trying to debug this weird issue:

Log::debug($request->session()->token(). ', ' . $token);

输出如下:

[2015-03-21 17:04:22] local.DEBUG: XJhAXXQumM0JLX9tFcQn1tQZMI1FtglDFuhi8abT, XJhAXXQumM0JLX9tFcQn1tQZMI1FtglDFuhi8abT  
[2015-03-21 17:04:34] local.DEBUG: XJhAXXQumM0JLX9tFcQn1tQZMI1FtglDFuhi8abT, XJhAXXQumM0JLX9tFcQn1tQZMI1FtglDFuhi8abT  
[2015-03-21 17:04:36] local.DEBUG: snE0IERJ1VY0o4qmSMuHb4wH9lhQUf5ZtVObOFnR, XJhAXXQumM0JLX9tFcQn1tQZMI1FtglDFuhi8abT  
[2015-03-21 17:04:36] local.ERROR: exception 'Illuminate\Session\TokenMismatchException' in vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php:47
Stack trace:
[...]
[2015-03-21 17:07:30] local.DEBUG: XJhAXXQumM0JLX9tFcQn1tQZMI1FtglDFuhi8abT, XJhAXXQumM0JLX9tFcQn1tQZMI1FtglDFuhi8abT

如您所见,前两个请求成功,第三个请求失败,第四个请求再次成功.我一直在使用Fiddler和Chrome网络工具,并且可以确认对于所有请求,已将完全相同的数据发送到服务器.

As you can see, the first 2 requests succeed, the 3rd one fails and the 4th one succeeds again. I've been using Fiddler and Chrome network tools and I can confirm that the exact same data was sent to the server for all requests.

因此,令牌似乎在服务器端发生了变化.奇怪的是,会话文件中的令牌似乎没有更改,并且错误的令牌始终是我之前从未见过的字符串,但是总是以某种方式恢复为原始字符串.

So it seems the token changes on the server side. The weird thing is that the token in the session file doesn't seem to change, and the wrong token is always a string I haven't seen before, but always gets reverted to the original string somehow.

这种情况经常发生,所以确实很烦人.首先,我认为这可能与数据库会话驱动程序有关,但是我现在正在使用文件驱动程序,并且这种情况仍在发生.

This happens pretty often, so it's really annoying. First I thought it may be something about the database session driver, but I'm using the file driver now and it's still happening.

更新

我一直遇到这个问题.我在不同的PC和使用php artisan serve的不同项目中使用它.我也在不同的服务器和不同的项目(nginx 1.6.2,PHP 5.6.7)上使用它.

I keep having this problem. I have it on different PC's and different projects using php artisan serve. I also have it on different servers and different projects (nginx 1.6.2, PHP 5.6.7).

我不是唯一遇到此问题的人.

由于它是随机发生的,因此调试起来非常困难,有时它不会出现一段时间,然后突然连续或多次发生.通过简单地重新提交POST请求,该请求有时会再次起作用,或者有时会导致另一个异常.

It's pretty hard to debug as it happens randomly, sometimes it doesn't show up for some time and then suddenly it happens many times in a row, or just once. By simply resubmitting the POST request it sometimes works again, or sometimes results in another exception.

在所有项目中,我添加到composer.json的唯一内容是"illuminate/html": "5.*".所有作曲家程序包都是最新的.

Only thing I added to composer.json in all projects is "illuminate/html": "5.*". All composer packages are up-to-date.

一旦我有了关于这个非常奇怪的问题的更多信息,我将立即更新此问题.

I'll update this question as soon as I've more info regarding this really weird problem.

另一个更新

我创建了一个新的L5项目,并添加了一些最少的代码来重现此错误.我所做的更改可以在此处(以及完整的测试项目)中看到).我现在将尝试对该项目进行一些调试.

I created a new L5 project, and added some minimal code to reproduce this error. The changes I made can be seen here (along with the complete test project). I'll try some debugging with this project now.

推荐答案

这是Laravel 5中针对某人人员的一个已知问题.

This is a known issue with Laravel 5 for some people.

这里有关于此主题的公开Github问题票: https://github.com/laravel/framework/issues /8172

There is an open Github issue ticket on this topic here: https://github.com/laravel/framework/issues/8172

原因尚不清楚,并且已经持续了一段时间.有很多聪明的人正在研究它-但是问题的明显随机性使其难以调试.

The cause is not yet known, and it has been going on for a while. There are a lot of smart people looking into it - but the apparent randomness of the issue is making it difficult to debug.

我建议您将信息提供给该票证,并留意那里的更多信息.

I suggest you contribute your information to that ticket and keep an eye there for further information.

这篇关于L5随机TokenMismatchExceptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆