Location: PHPKode > scripts > Distributed Session Manager > phpdsm.html
		<title>PHP Distributed Session Manager Class</title>
		<style type="text/css">

			body {
				font-family: Verdana, Arial, sans-serif;
				font-size: 85%;
				margin: 10px;
			h1 {
				font-family: Trebuchet MS, Verdana, Arial, sans-serif;
				background-color: #eee;
				padding: 10px;
				margin: -10px -10px 10px -10px;
				border-bottom: 1px solid #ccc;
				color: darkblue;
			h2 {
				font-family: Trebuchet MS, Verdana, Arial, sans-serif;
				font-weight: normal;
				color: darkred;
			p, div.notice {
				margin-left: 20px;
			div.notice {
				padding: 10px;
				border: 1px solid #ccc;
				background-color: #f8f8f8;
				color: #666;
				font-style: italic;

		<h1>PHP Distributed Session Manager Class</h1>
		<h2>What is it?</h2>
			The <b>PHP Distributed Session Manager Class</b> provides a simple but scalable solution
			for managing session data in a large cluster.<br>
			<img src="sessions.png"><br>
			1. Standard PHP sessions on a single webserver<br>
			2. Sessions stored on a central database server (single point of failure)<br>
			3. Sessions distributed among many database servers using the Distributed Session Manager Class
			<li>Unlimited amount of simultaneous sessions</li>
			<li>Uses Linux, Apache, MySQL and PHP only; no <i>memcached</i> or <i>Zend Platform</i> required.</li>
			<li>Configurable level of redundancy; no data loss when a server crashes.</li>
				<li>Apache 1.3.x or better</li>
				<li>PHP 4.3.x or better</li>
			<li>Database servers</li>
				<li>MySQL 4.x or better</li>
		<h2>How does it work?</h2>
			The algorithm behind the class is inspired by a Distributed Hash Table (DHT). The class loads a list
			of Session Stores (each running a stand-alone instance of MySQL). It then seeds PHP's pseudo randomizer 
			with the CRC32 hash of the session ID and 'randomly' shuffles the list of Session Stores.
			Because PHP's randomizer isn't random, but pseudo random, it produces the same 'random' order every time for the same seed.
				$stores = array( 'store1', 'store2', 'store3', 'store4' );<br>
				srand( crc32( $session_id ) );<br>
				shuffle( $stores );
			<b>Reading session data</b><br>
			The Session Manager class attempts to connect to each of the Session Stores in order until a connection has been established
			succesfully. It then fetches the session's data from that Session Store and returns it to the script.
			<b>Writing session data</b><br>
			The Session Manager class attempts to connect to each of the Session Stores in order. If a connection has been succesfully established,
			it writes the data to the connected Session Store. This process is repeated until NUM_COPIES is met.

		<h2>Credits &amp; licensing</h2>
			The PHP Distributed Session Manager Class is developed by Robin Schuil (<a href="mailto:hide@address.com">hide@address.com</a>).<br>
			All code is released under the <a href="http://www.gnu.org/copyleft/gpl.html">GNU GPL licence</a> and were published on the 12 July 2006.
			<a href="phpdsm.zip">Click here to download</a> the PHP Distributed Session Manager class source code. Enjoy!
		<div class="notice">
			Warning: This product and it's documentation is experimental and still under construction.
Return current item: Distributed Session Manager