使用 CodeIgniter Session 类时数据库负载过重?

发布于 2024-11-02 10:37:06 字数 309 浏览 3 评论 0原文

在阅读了 CodeIgniter 如何处理会话后,我担心将会话配置为从数据库存储和检索时对性能的影响。

这是来自 CI 文档:“当数据库中存在会话数据时,每次在用户的 cookie 中找到有效会话时,都会执行数据库查询来匹配它。”

那么每个 AJAX 调用、我请求的每个 HTML 片段都会有这样的开销吗?对于试图扩展的系统来说,这可能是一个巨大的问题!

我猜想 CI 会更好地实现它:在会话记录中编码时包含 MD5 哈希来覆盖 sessionID+时间戳。然后,每当重新生成 sessionID 时,每隔 X 分钟检查数据库中的会话记录。我错过了什么吗?

After reading about how CodeIgniter handles sessions, it has me concerned about the performance impact when sessions are configured to be stored and retrieved from the database.

This is from the CI documentation: "When session data is available in a database, every time a valid session is found in the user's cookie, a database query is performed to match it."

So every AJAX call, every HTML fragment I request is going to have this overhead? That is potentially a huge issue for systems that are trying to scale!

I would have guessed that CI would have implemented it better: include the MD5 hash to cover both the sessionID+timestamp when encoding them in the session record. Then only check the database for the session record every X minutes whenever the sessionID gets regenerated. Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缘字诀 2024-11-09 10:37:06

您可以使 AJAX 请求使用不同的控制器,例如 Ajax_Controller 而不是 MY_Controller。 MY_Controller 将加载 Session 类,但 Ajax_Controller 不会。这样,当您调用 AJAX 时,它不会触及会话数据,因此不会对数据库进行任何不必要的错误调用。

如果您正在自动加载 Session 类,也许您可​​以尝试为 AJAX 请求卸载它?我从未尝试过,但这里讨论了http://codeigniter.com/forums/viewthread /65191/#320552 然后执行类似的操作

if($this->input->is_ajax_request()){
// 卸载会话类代码放在这里
}

You can make your AJAX requests use a different controller, for example Ajax_Controller instead of MY_Controller. MY_Controller would load the Session class but the Ajax_Controller doesn't. That way when you call to your AJAX, it doesn't touch session data and therefore doesn't make any erroneous calls to the database that aren't necessary.

If you are autoloading the Session class, maybe you can try unloading it for the AJAX requests? I've never tried it but it's talked about here http://codeigniter.com/forums/viewthread/65191/#320552 and then do something like this

if($this->input->is_ajax_request()){
// unload session class code goes here
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文