Alex Rivera | Logout

Are PHP sessions hard to scale across a distributed system?

Asked 2008-11-01T06:03:05.047
10

At work we do almost everything in Java and perl, but I wanted to build out a feature using PHP and sessions. Some peeps thought that it was a bad idea to try to do PHP sessions on our system, cause it's distributed to many servers. What would the specific problem be?

Edit
Report

1 Answer

0

Quite a vague question, but I would say the problem is bigger than mentioned in the answers. Sure you can override how loading and saving cookies, but there's a cost to it, too. For example, you will have to consider the following scenarios/questions:

  • If you are putting the cookies on another host, how will this affect the speed of your cookies? That obviously depends on how many writes/reads you make.
  • Are you doing this to increase speed or to have failover? The answer will definitely lead to different solutions:
    • In case you are doing this for failover, how will you handle if your webserver(s) can't access your session store because network link goes down? What if your session store goes down? You will have to solve this using some kind of master-master replication, possibly running that distributed session store on the same machine as the webserver for extra high availability (if all sessions can fit in memory). Have a look at Riak or similar for master-master replication.
    • In case you are simply doing this for speed, I would use apache, nginx or (fastest) haproxy to simply do load balancing based on client IP address. That way you don't have to bother with setting up a distributed session store. Sure, if one of your PHP-instances goes down your users will loose their cookies, but maybe that's not a problem. It's up to you.
answered 2011-12-09T10:05:57.120

Your Answer