title: Has anyone created a PHP Session-like class in user code (not native)?
body: <p>The native PHP Session functionality is great, but it's ultimately a singleton. There are times when you need to maintain state for multiple apps and in the scope of an already-started session (e.g. in an app framework). Technically one can stop/restart a session after changing <code>session_name()</code>, but this is impractical/impossible/unsafe within most apps. Using a shared <code>session.save_path</code> is also not an option if one app stores session data with a non-disk adapter.</p>
  
  <p>There's no reason the functionality in native sessions can't be done in user code, so has anyone done this?</p>
  
  <p><strong>Update 1:</strong> <a href="https://bitbucket.org/ellislab/codeigniter-reactor/src/0bff9acdc441/system/libraries/Session.php" rel="nofollow">CI_Session</a> is indeed a userland implementation with some useful code, but it's highly coupled to CodeIgniter.</p>
  
  <p><strong>Update 2:</strong> Here's an API that would be great:</p>
  
  <pre><code>// setup
  $saveHandler = new UserlandSession_SaveHandler_Files('5;/tmp');
  $sess = new UserlandSession($saveHandler);
  $sess-&gt;name('PHPSESSID2');
  $sess-&gt;gc_maxlifetime = 86400;
  $sess-&gt;setProxy($state); // passed by ref
  // usage
  $sess-&gt;start(); // stored string unserialized to $state
  $state['foo'] = 'bar';
  $sess-&gt;write_close(); // $state serialized to storage
  </code></pre>
  
  <p><strong>Update 3:</strong> <a href="https://github.com/mrclay/shibalike/tree/master/src/Shibalike/Util" rel="nofollow">I've written an implementation</a> for PHP5.3.</p>