是否有人将数据库数据存储在PHP $ _SESSION中?
I just joined a project, and have been going over the code. We need to export a lot of data out to Excel for our internal users. There are roughly 5 people who would have access to this functionality at a given time. In order to output to Excel, here's what I found:
我刚刚加入了一个项目,并且一直在查看代码。我们需要为内部用户将大量数据导出到Excel。大约有5个人可以在给定时间访问此功能。为了输出到Excel,这是我发现的:
- retrieve data from DB, store in $_SESSION
show HTML page view of data
显示数据的HTML页面视图
when the user wants to export
当用户想要导出时
- retrieve the DB data from $_SESSION
- create a string in memory of a CSV
- print the HTTP Headers with Excel as the filetype
- print out the CSV formatted strings
从$ _SESSION中检索数据库数据
在CSV的内存中创建一个字符串
使用Excel作为文件类型打印HTTP标头
打印出CSV格式的字符串
从DB检索数据,存储在$ _SESSION中
This storage in $_SESSION is happening even when the user is not going to export. This strikes me as terribly inefficient, since the $_SESSION variable could explode in size, since each of the DB table retrievals can be up to 30MB per table, and the expiration on $_SESSION is set to 24 hours. So potentially, there could up to 5 users in the system, with up to 150MB $_SESSION variables. Sound about right?
即使用户不打算导出,$ _SESSION中的此存储也会发生。这对我来说非常低效,因为$ _SESSION变量的大小可能会爆炸,因为每个数据库表检索的每个表最多可以达30MB,而$ _SESSION的过期时间设置为24小时。因此,系统中最多可以有5个用户,最多150MB $ _SESSION变量。听起来对吗?
Has anyone else ever seen something like this? Is this like a bootleg Memcache? Wouldn't it be best to just write the data to a flat-file that's updated once every few hours?
有没有人见过这样的东西?这是一个盗版Memcache吗?将数据写入每隔几小时更新一次的平面文件不是最好的吗?
4 个解决方案
#1
2
I do store database some data in session, like ID or small object that I use on every page.
我在会话中存储数据库的一些数据,比如我在每个页面上使用的ID或小对象。
But when it come to larger dataset that I can't extract on the fly for each page load, I often prefer to store them in a MEMORY/HEAP table ( or a temporary file ), and just store an ID in the session so I'll be able to extract them easily.
但是当涉及到每个页面加载无法动态提取的更大的数据集时,我经常更喜欢将它们存储在MEMORY / HEAP表(或临时文件)中,并且只在会话中存储ID以便我能够轻松地提取它们。
You might want to take a look at this question about session max size: Maximum size of a PHP session
您可能想看一下有关会话最大大小的问题:PHP会话的最大大小
更多相关文章
- 数据类型和运算符 MySQL学习笔记
- mysql 数据库整体运行状态确认思路
- Wordpress数据库类- MySQL类型。
- 向数组添加一组数据库列的问题
- c#操作mysql事务是不是要在一个数据库连接内完成?
- 如何在MySQL数据库和JPA中使用Spring Boot?
- 无法连接远程MySQL数据库的解决方案
- MySql数据库安装
- mysql 大数据量高效分页查询