Laravel 5.1随机删除会话数据 [英] Laravel 5.1 randomly dropping session data

查看:61
本文介绍了Laravel 5.1随机删除会话数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Laravel 5.1应用程序有一个奇怪的问题.

I have a strange issue with a Laravel 5.1 application.

间歇性地删除会话数据.我通过编写一些中间件来检测到这一点,该中间件将该请求的会话内容写入日志文件.尽管会话ID(Session::getId())不变,但使用Session::all() 检索的会话数据中的_token的值却是.

Intermittently, it’s dropping session data. I’m detected this by writing some middleware that writes the contents of the session for that request to the log file. Although the session ID (Session::getId()) doesn’t change, the value of _token in the session data retrieved with Session::all() does.

正如我所说,这是间歇性发生的.我可以多次刷新相同的URL,然后随机刷新一次该会话数据,并且_token值与以前的请求不同.

As I say, this happens intermittently. I can refresh the same URL multiple times, and then randomly on one refresh the session data’s gone, and the _token value’s different from the previous requests.

这是什么原因造成的?我还注意到flash对象不在已删除"会话数据中.

What would cause this? I’ve also noticed the flash object isn’t in the "dropped" session data.

以下是日志的摘要.您可以在最后两行看到session_data键的内容随机更改形状",但是会话ID保持不变.

Below is a snippet of the log. You can see the content of the session_data key randomly changes "shape" in the last two lines, but the session ID remains constant.

此外,不确定是否相关,但是我已启用 DebugBar .

Also, not sure if it’s pertinent, but I have DebugBar enabled.

更新:通过调试,我发现在某些页面上加载的会话完全是 empty ,例如,没有_token(因此有一个新的生成).没事.

UPDATE: Through debugging, I’ve found that on some page loads the session is completely empty, as in, no _token (hence a new one getting generated). Nothing.

推荐答案

  1. 如果使用文件驱动程序,则可能会在并发请求上遇到争用条件.然后,该文件被截断,Laravel无法读取它,因此刷新了会话.竞赛条件也可能导致您无法在比赛中投入某些东西的症状.这往往是随机的,因此很难调试.根据Laravel团队的说法,这是文件驱动程序的已知限制,并且似乎没有得到解决,因此我建议使用其他驱动程序.这将解决您的随机会话刷新问题,但仍会引入对未添加的会话进行更改的可能性.据我所知,此时使用Laravel 5.1,您必须自己进行管理.

  1. If you're using the file driver, you could run into race conditions on concurrent requests. The file then gets truncated, Laravel can't read it, so it refreshes the session. Race conditions can also lead to a symptom where something you're putting to the session just doesn't get put. This tends to be random, so it's very hard to debug. According to the Laravel team, this is a known limitation of the file driver and it does not appear to be getting fixed, so I would suggest using a different driver. This would fix your issue of random session refreshes, but it still introduces a possibility of making a change to the session that doesn't get added. As far as I know, at this point with Laravel 5.1, you'll have to manage that yourself.

以某种方式您的会话数据太长而被截断.如果您使用的是数据库驱动程序(尚未测试其他驱动程序),并且尝试保存长度超过字段长度的会话数据,则后续请求将无法从该会话中提取,并且您将进行新的会话.如果此问题是在会话数据非常短的情况下随机发生的,则可能是上面列出的原因.

Somehow your session data is too long and being truncated. If you're using the database driver (haven't tested other drivers), and you try to save session data that's longer than the field length, then subsequent requests won't be able to pull from this session, and you'll wind up with a new session. If this issue is happening randomly with very short session data, then it's probably the cause listed above.

这篇关于Laravel 5.1随机删除会话数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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