如何在$ _SESSION中存储数据与memcache(d)不同?
The obvious difference is that when stored in memcache(d)
data becomes available cross the system. Sessions store data per user, though, session_id()
could theoretically be used to share this data with more users.
However, in terms of performance, speed and memory usage - is there a difference?
明显不同的是,当存储在 但是,在性能,速度和性能方面 内存使用情况 - 有区别吗? p>
div> memcache(d) code>中时,数据变为可用 系统。 会话存储每个用户的数据,但理论上可以使用
session_id() code>与更多用户共享此数据。 p>
PHP sessions are stored in the filesystem by default. You can modify this behaviour so that they are saved in a database, or in your case memcached.
So in terms of performance, memcached is generally faster than the filesystem. This obviously depends on your environment.
Well, you can simply use memcache for $_SESSION
. That's definitely faster, as it doesn't require a lot of calls to a PHP API, but it goes straight to the C API instead.
Small performance bonus though, PHP really isn't all that slow.
If you're going to compare memcache with filesystem sessions: use memcache. Really, you should, as that simply stores them in memory instead of storing them on the filesystem. A lot faster. Of course, you do risk losing session data if the memcache server overloads. Memory usage of memcache will of course be higher than the filesystem alternative.
Sessions are stored in either a file or database. Memcache is stored in memory for faster access.
Apples and oranges. They achieve two entirely different things. Your real question is file storage vs. memcache. You could theoretically store session info in memcache instead of the file based storage. Then the performance of session would be identical to directly pushing a value to memcache.
All things being equal, memcache performs far better than file caching. In terms of memory, when you read the file to get the data (in this case the session file), it goes into memory anyhow, so its doesn't save any space. In fact if multiple requests happen to apache different worker process may need to read the same session file--each using their own chunk of memory until the worker process is reaped. Using memcache, this doesn't happen.