会话变量与Mysql表 [英] Session variables vs. Mysql table

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

问题描述

我打算在会话变量中保存用户常用的参数(即名称,图片等),而不是每次需要时都从MySQL表中提取参数.从理论上讲,与数据库相比,将常用参数保存在变量中应该更有效,但是由于我不确定SESSION变量的保存方式,所以我不太确定这是否成立.有谁知道是否提取信息.从SESSION变量比查询MySQL表更有效?

I'm planning on saving my users often used parameters, i.e. name, picture, etc, in session variables as opposed to pulling then from the MySQL table each time they are needed. Saving often used parameters in variables as opposed to a database in theory should be more efficient, but because I'm not sure how SESSION variables are saved I'm not too sure if this is true. Does anyone know if pulling info. from a SESSION variable is more efficient than querying the MySQL table?

变量"一词被宽松地使用,因为会话变量"存储在服务器临时目录中的文件中.

The term variable is used loosely as SESSION "variables" are stored in files in the server's temporary directory.

您会认为读取文件比读取数据库要花费更多,我的意思是数据库本质上是一个文件,但是为此目的而进行了优化,而不是临时会话文件"

You would think reading files is more costly than reading a database, I mean that is what a database is essentially, a file, but it is optimized for this purpose as opposed to "temporary session files"

推荐答案

是的,从会话变量中提取信息比在数据库中查询该信息更有效.但是,加载会话变量 INTO 信息需要从服务器文件系统中读取文件并读取到RAM中,这取决于许多因素(磁盘速度,IO负载,数据库速度等),可能会更慢或比从数据库读取相同的信息更快.没有有关您的特定设置的信息,这很难说.要记住的一件事是,如果您计划增长并使用多个Web服务器,则需要编写一些自定义会话处理程序,以将您的会话存储到中央服务器(可能是数据库),内存缓存或共享安装中指向所有Web服务器可以用来获取会话文件的位置.

Yes, pulling information from a session variable is more efficient than querying a database for that info. However, loading the information INTO the session variables requires reading a file off of your servers file system and into RAM, which depending on many factors (disk speed, IO load, db speed, etc) might be slower or faster than reading the same information from a DB. Without information on your specific setup, it's hard to say. One thing to keep in mind, if you plan on growing and using more than one web server, you will need to write some custom session handlers to either store your sessions to a central server (possibly a database), memcache, or a shared mount point where all your web servers can go to fetch the session files.

最后,将某些内容放入会话中并从那里使用 可能比每次从数据库中加载都更有效,但是您仍要从某处加载它,,因此,有关您的硬件和设置的知识将是您的最佳指南.

In the end, putting something into the session and using it from there can be more efficient than loading it from the DB every time, but you are still loading it from somewhere, and so, knowledge of your hardware and your setup will be your best guide.

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

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