<p>PHP stores its session information on the file system of the host of the server establishing that session.  In a multiple-host PHP environment, where load is unintelligently distributed amongst each host, PHP session variables are not available to each request (unless by chance the request is assigned to the same host -- assume we have no control over the load balancer).</p>

<p><a href="http://porteightyeight.com/archives/121-The-Hitchhikers-Guide-to-PHP-Load-Balancing.html" rel="noreferrer">This site, dubbed "The Hitchhikers Guide to PHP Load Balancing"</a> suggests overriding PHPs session handler and storing session information in the shared database.</p>

<p>What, in your humble opinion, is the <em>best</em> way to maintain session information in a multiple PHP host environment?</p>

<p><strong>UPDATE:</strong> Thanks for the great feedback.  For anyone looking for example code, we found a <a href="http://www.devshed.com/c/a/PHP/Storing-PHP-Sessions-in-a-Database/" rel="noreferrer">useful tutorial on writing a Session Manager class for MySQL</a> which I recommend checking out.</p>

[{'answer_id': 76800, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 1, 'selected': False, 'text': '<p>Storing the session data in a shared db works, but can be slow. If it\'s a really big site, <a href="http://en.wikipedia.org/wiki/Memcached" rel="nofollow noreferrer">memcache</a> is probably a better option.</p>\n'}, {'answer_id': 76881, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': True, 'text': '<p>Database, or Database+Memcache.  Generally speaking sessions should not be written to very often.  Start with a database solution that only writes to the db when the session data has <em>changed</em>.  Memcache should be added later as a performance enhancement.  A db solution will be very fast because you are only ever looking up primary keys.  Make sure the db has row locking, not table locking (myISAM).  MemCache only is a bad idea... If it overflows, crashes, or is restarted, the users will be logged out.</p>\n'}, {'answer_id': 76947, 'author': 'Peter Bailey', 'author_id': 8815, 'author_profile': 'https://Stackoverflow.com/users/8815', 'pm_score': 1, 'selected': False, 'text': "<p>Depending on your project's budget, you may also consider Zend Platform for your production machines, which in addition to a bunch of other great features, includes configurable session clustering, which works sort of like a CDN does.</p>\n"}, {'answer_id': 77192, 'author': 'Jilles', 'author_id': 13864, 'author_profile': 'https://Stackoverflow.com/users/13864', 'pm_score': 2, 'selected': False, 'text': "<p>Whatever you do, do not store it on the server itself (even if you're only using one server, or in a 1+1 failover scenario). It'll put you on a dead end.</p>\n\n<p>I would say, use Database+Memcache for storage/retrieval, it'll keep you out of Zend's grasp (and believe me things do break down at some point with Zend). Since you will be able to easily partition by UserID or SessionID even going with MySQL will leave things quite scalable.</p>\n\n<p>(Edit: additionally, going with DB+Memcache does not bind you to a comercial party, it does not bind you to PHP either -- something you might be happy for down the road)</p>\n"}]
['https://Stackoverflow.com/questions/76712', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4330/']