Does a session variable stay in memory in php

十年热恋 提交于 2019-12-06 10:31:28

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.

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.

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

Yes, It will stay in memory for the life of the session. Your 1mb is far from the max capacity it can hold (default I think is 128MB). However, test both ways if it would be more efficient to just read from the file.

gusridd

It will be stored using a file in the server. You can see session files in the path defined by session_save_path. Depending on the file system, the file could stay in memory depending on usage, but basically is a file.

I forgot to mention that the info was obtained mainly from here: Where and How is data stored in a session?

session is stored either in file or in database, it does not consume PHP memory(server memory).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!