会话变量是否保留在 php 的内存中

问题描述:

如果我将文本文件的内容存储在 php 的会话变量中,它会在该会话期间保留在内存中吗?

If I store contents of a text file in a session variable in php, will it stay in memory for the period of that session?

我有一个小项目,我需要在那个超过 1mb 的特定文本文件中执行搜索.如果会话变量保留在内存中,我正在考虑使用它,这样我就不必一次又一次地读取该文件.

I have a small project where I need to perform searches in that specific text file which is just over 1mb. I'm thinking of using a session variable if it stays in memory, so that I don't have to read this file again and again.

不,会话将默认存储在文件中(例如在/tmp 中).当然,您可以将内存与例如 memcached 一起使用.也可以将数据库用于会话.

No, sessions will be stored default in files (e.g. in /tmp). Of course, you can use the memory with for example memcached. It's also possible to use a database for sessions.

但是,如果您有足够的内存,请将您的会话存储在内存中(非常快).Memcached 是一个很棒的分布式内存对象缓存系统.有关详细信息,请参阅 http://memcached.org.

But, if you have enough memory, store your sessions in memory (very fast). Memcached is a great distributed memory object caching system. See http://memcached.org for more information.

这里是关于 php 的 memcached 扩展:http://php.net/manual/en/book.memcached.php

And here about the memcached extension for php: http://php.net/manual/en/book.memcached.php