PHP的会话与MySQL的速度 [英] php session vs mysql speed

查看:89
本文介绍了PHP的会话与MySQL的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用许可系统.在每个页面中,都需要检查用户是否有权这样做.我有两种选择,将数据存储在会话变量中(仅在登录期间更新),或者每次都在数据库中查询信息. 哪个更快?

i am working a on a permission system. In each page it will need to check whether if the user has the permission to do so. I have two choices, store the data in a session variable (which is only updated during login) or query the database for the information every time. Which is faster?

我意识到,如果许可权发生更改,我将需要更新会话变量,因此用户需要重新登录以查看"许可权的更改,但这不是决定因素,只有速度是决定因素./p>

I realized that if the permission changes, I will need to update the session variable, therefore the user needs to relogin to "see" the changes in permission, but that is not a factor in the decision, only speed is.

推荐答案

SESSION与DB的速度取决于许多因素:

Speed of SESSION vs. DB is dependent on a number of factors:

  • 会话变量中将存储多少数据
  • 会话变量的实际后备存储是什么(如果是数据库支持的会话,则基本上是同一时间)

我可以说,对于少量数据,基于文件的会话变量将比数据库访问快.

I can tell that for small amounts of data, file based session variables will be faster than DB access.

您需要对其进行度量,以在应用程序中的两种方法之间获得相关的比较.我个人怀疑这样做是否会导致不寻求会话解决方案.

You need to measure it to obtain a relevant comparison between the two methods in your application. I personally doubt that it will make a such a difference as to not go for the session solution.

这篇关于PHP的会话与MySQL的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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