Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a session variable stay in memory in 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?

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.

like image 294
head_scratcher Avatar asked Oct 20 '25 04:10

head_scratcher


1 Answers

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

like image 95
schellingerht Avatar answered Oct 21 '25 19:10

schellingerht



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!