PHP:默认 /tmp 会话 VS session_set_save_handler() 性能
在我的研究过程中,我发现了关于这个问题的两个方向的观点。为了澄清这个问题,我们将不胜感激。
我们意识到将会话数据存储在数据库中具有明显的安全优势。
选项 1:
使用文件系统上的默认会话存储(默认为/tmp)
选项 2:
使用 session_set_save_handler() 来 将会话数据存储在/a中 数据库。
我的问题是:
- 在高流量网站上,什么示例可以提供最佳性能?
- 这是系统硬件的问题吗?该特定站点当前的瓶颈在哪里?在这种情况下,该站点主要用于显示数据库中的特定用户数据。这可能是一个需要服务器故障输入的问题。
- 该网站可能很快就会传播到多个服务器,以处理来自世界其他地区的负载和可访问性。想想 CDN。这会影响我的决定吗?我认为如果将不同计算机之间的会话信息存储在数据库中,管理它会更容易。
During my research I have found opinions pointing in both directions on this issue. A discussion would be appreciated to clarify this issue.
We are aware of the obvious advantageous security aspects on storing the session data in the database.
Option 1:
Using the default session storage on the filesystem (defaults to /tmp)
Option 2:
Using session_set_save_handler() to
store the session data in the/a
database.
My questions are:
- On a high traffic site, what example would give the best performance?
- Is this a matter of system hardware and where the current bottlenecks on this specific site are? In this case, the site is heavily pointed toward displaying specific user data from the database. Possibly this would be a question in need of serverfault input.
- The site will probably have to propagate on to multiple servers soon, to deal with load and accessibility from other parts of the world. Think CDN. Does this affect my decision? I'm thinking it would be much easier to manage session information between the different computers if it is stored in the database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
高流量站点不喜欢存储到 /tmp 的原因是因为它们使用负载平衡。负载平衡有效地交换了哪台机器传送数据。如果会话位于 /tmp 中,则并非所有计算机都具有相同的 /tmp 目录,这意味着您的用户可能会无缘无故地开始显示为已登录或已注销。
这就是为什么有些网站将数据存储在数据库中的原因。然而,这是无效的,因为对站点的每个请求都意味着从数据库中提取信息,这意味着不断连接,将数据从文本转换为数组等等。
因此,有第三种选择 - 使用 Memcache 存储会话数据。这真的很简单,如果你用谷歌搜索一下,你就会找到答案,并且你可以在 5 分钟内完成整个设置。
Reason why storing to /tmp isn't favored on high traffic sites is because they use load balancing. Load balancing effectively swaps which machine delivers the data. If the session is in /tmp, not all machines have the same /tmp directory which means your users might start appearing logged in or logged out for no apparent reason.
That's why some sites store data in databases. However, that's ineffective as every request to the site means pulling info from db, which means connecting constantly, transforming data from text to an array and so on.
So, there's the third option - store the session data with Memcache. It's really easy, and if you google-fu a bit about this, you'll find answers and you can set the whole thing up in less than 5 minutes.