#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    139
    Rep Power
    10

    How do php sessions work on a server farm?


    Where is the session data stored? How is it known where to find it? Basically- how does it work. I could only find ASP related info on the subject.
    Thanks,
    Dan

    Operating system ubuntu 12.04
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Sessions are stored on the filesystem in the /tmp directory, unless you've overwritten the session storage location in php.ini or you've set a custom session save handler.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    139
    Rep Power
    10
    Thanks. I was wondering specifically about the server farm though. when the load is balanced acrossed multiple web servers, is the session data magically spread out across all servers or how does that work, generally speaking?
    Thanks,
    Dan

    Operating system ubuntu 12.04
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    unless you've overwritten the session storage location in php.ini or you've set a custom session save handler.
    Not sure what else I can tell you there. You do it yourself, someone wrote it, and that person chose where to store the sessions. It's no more magical than the question "where does the username get stored?" Somewhere. If you want to know where, check the code.

    Usually, clustered sessions are stored in memcache or a database. Usually.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    I was wondering specifically about the server farm though. when the load is balanced acrossed multiple web servers, is the session data magically spread out across all servers or how does that work, generally speaking?
    With the standard PHP session handling code, no, the data is not magically spread out across all of the servers and session handling will break if you load balance servers without doing something to compensate for the fact that session data is not shared.

    There are two approaches for handling sessions behind load balanced servers. One is to share the same session database between all of the servers. This is what ManiacDan suggested. This requires you to implement a custom session handler and have a database server to support the session load.

    The other approach is session stickiness. This is a load balancer setting that causes the load balancer to set a cookie on the client that indicates which web server that client is using. All of their future requests are then routed to that same web server, so there is no need to share sessions between the servers. This model doesn't require any deviation from the standard PHP session handling code and is the one that I see most frequently.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo