使用 PHP $_SESSION 变量存储大量数据
我目前在 $_SESSION 变量中存储了大量数据。我这样做是为了不需要继续访问数据库。
我应该担心共享服务器上的内存问题吗?
服务器可以处理存储在 $_SESSION 变量中的大量数据吗?
I'm currently storing a fair amount of data in the $_SESSION variable. I'm doing this so I don't need to keep accessing the database.
Should I be worried about memory issues on a shared server?
Can servers cope with large amounts of data stored in the $_SESSION variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的 - 每次请求时会话数据都会加载到脚本的内存中。因此,您面临着打破各个脚本内存限制的风险。即使没有达到极限,这也确实是低效的。
按需从数据库访问数据要好得多。
Yes - session data is loaded into the script's memory on every request. Hence, you are at risk of breaking the individual per-script memory limit. Even if you don't hit the limit, this is really inefficient.
Accessing data from the database on demand is much better.
..除了@Pekka 所写的之外:
PHP 会话不能替代缓存解决方案!
您应该调查您的服务器是否有可用的 APC。您应该在从数据库访问信息的层之上使用它(假设您实际上有面向对象的代码)。
.. in addition to what @Pekka wrote:
PHP sessions an not alternative to a caching solution !
You should investigate if your server has APC available. You should use that on top of layer which accesses information from database (assuming you actually have an OO code).