Someone wanted the PHP code were were using to store our sessions within memcached. <br><br>Well here you go.<br><br>replace tailrank_ to something less proprietary.... and you'll need your own version of tailrank_memcache_get_instance to get a copy of your memcached object.
<br><br>you to call session_start() at the beginning of your script and session_commit() at the end.<br><br>you'll also need to change the domain from <a href="http://tailrank.com">tailrank.com</a> to your domain (obviously)
<br><br>If you make any changes or fix any bugs please let me know.<br><br>This is hereby licensed under the GPL, BSD, and public domain so have fun! :)<br><br><?php<br><br>/*<br> * Send mail but also include the From header.
<br> */<br>function tailrank_session_start() {<br> <br> //For machines that already have this session loaded this will merely be<br> //redundant.... <br><br> global $_SESSION;<br> $my_memcache = tailrank_memcache_get_instance();
<br><br> $cookie = $_COOKIE[ "SESSIONID" ];<br><br> if ( $cookie != null ) {<br><br> $key = "session3:" . $cookie;<br> $session_data = $my_memcache->get( $key );<br><br> if ( $session_data != null ) {
<br> $_SESSION = unserialize( $session_data );<br> }<br><br> } else {<br><br> //call the default php session start code to init the session on this<br> //client.<br><br> srand((double)microtime()*1000000);
<br> $cookie = rand( 0, 100000000000 ); <br><br> $_COOKIE[ "SESSIONID" ] = $cookie;<br><br> //create a new local aray for the session.<br> $_SESSION=array();<br><br> $expire = time() + 365 * 24 * 60 * 60 * 24;
<br> setcookie( 'SESSIONID', $cookie, $expire, "/", ".tailrank.com" );<br><br> }<br><br>}<br><br>function tailrank_session_commit() {<br><br> //serialze $_SESSION<br><br> global $_SESSION;
<br> $my_memcache = tailrank_memcache_get_instance();<br><br> if ( $_SESSION != null ) {<br><br> $session_data = serialize( $_SESSION );<br> $cookie = $_COOKIE[ "SESSIONID" ];<br> $key = "session3:" . $cookie;
<br><br> $my_memcache->set( $key, $session_data, false, 600 );<br><br> } <br><br>}<br><br>?><br clear="all"><br>-- <br>Founder/CEO <a href="http://Tailrank.com">Tailrank.com</a><br>Location: San Francisco, CA
<br>AIM/YIM: sfburtonator<br>Skype: burtonator<br>Blog: <a href="http://feedblog.org">feedblog.org</a><br>Cell: 415-637-8078