temporary_user_name
temporary_user_name

Reputation: 37098

Looking for elaboration on how sessions are stored for high-traffic sites?

I've been trying to understand where PHP (or other languages, really, I suppose the principle is the same) keeps session data server-side.

I read this question and this question, which both seem to indicate that it defaults to just creating ordinary files in the /tmp folder, files whose names match the session IDs stored in client-side cookies.

But that seemed ever so slightly odd to me.....what about high traffic sites with millions of concurrent users....do they really just have a giant folder full of session files? There's no database involved?

Upvotes: 1

Views: 74

Answers (2)

Brad
Brad

Reputation: 163438

Even on smaller sites, I don't really know that many people putting files in a directory for session storage. It's slow, and session data can be something you need access to quickly and frequently, depending on the site.

Very often, an in-memory data store like Redis will be used. Many of these type of databases enable basic sharding across multiple hosts, and simple forms of replication to enable the scaling of your session storage.

When you get to the scale of millions of concurrent users, your specific needs become much more amplified. How much data do you need to store in session? Can that data be replicated to others on a best-effort basis or must it be atomic? At this point, everyone does it a bit different but the principle is the same. Fast data accessible from everywhere it needs to be. Store as little as you can.

Upvotes: 3

tomcyr
tomcyr

Reputation: 661

Default session is in filesystem but You can configure your app to store Your session in memory cache like Memcached or Redis. So then You can have many web servers and many cache servers for your sessions.

Upvotes: 1

Related Questions