Has anyone created a class similar to PHP in user code (not native)?

The native functionality of the PHP session works fine, but ultimately it's a singleton. There are times when you need to maintain state for several applications and within the framework of an already started session (for example, within the application). Technically, you can stop / restart a session after changing session_name() , but this is impractical / impossible / unsafe in most applications. Using a shared session.save_path also not an option if one application stores session data with an adapter without a disk.

There is no reason why functionality in native sessions cannot be performed in user code, so has anyone done this?

Update 1: CI_Session is indeed a custom implementation with some useful code, but it is very closely related to CodeIgniter.

Update 2: Here's an API that would be great:

 // setup $saveHandler = new UserlandSession_SaveHandler_Files('5;/tmp'); $sess = new UserlandSession($saveHandler); $sess->name('PHPSESSID2'); $sess->gc_maxlifetime = 86400; $sess->setProxy($state); // passed by ref // usage $sess->start(); // stored string unserialized to $state $state['foo'] = 'bar'; $sess->write_close(); // $state serialized to storage 

Update 3: I wrote an implementation for PHP5.3.

+7
source share
2 answers

CodeIgniter has a session class that does not use native PHP sessions.

+2
source

I wrote UserlandSession in response to this.

This is a pure implementation of PHP "sessions" that can be used to connect a session between arbitrary PHP applications. It does not interfere with native sessions, has an OO storage API (more similar to PHP 5.4), and has an API similar to native sessions.

It comes with a file system and PDO repository of handlers and an interface to simplify creating your own.

0
source

All Articles