Class Session

Description

Session Class

Provides session handling via database instead of the file based session handling built into PHP. Using this class requires an array to be defined in place of the boolean true/false (on/off). If simply array(), the datasource will default to the value in $config['pickles']['datasource'] and if the table will default to "sessions". The format is as follows:

$config = array( 'pickles' => array( 'session' => array( 'datasource' => 'mysql', 'table' => 'sessions', ) ) );

In addition to the configuration variables, a table in your database must be created. The [MySQL] table schema is as follows:

CREATE TABLE sessions ( id varchar(32) COLLATE utf8_unicode_ci NOT NULL, session text COLLATE utf8_unicode_ci NOT NULL, expires_at datetime NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Note: The reason for not using a model class was to avoid a naming conflict between the Session model and the Session class itself. This will eventually be resolved when I abandon full 5.x support and migrate to 5.3+ (assuming that ever happens).

Located in /classes/Session.php (line 51)

Object
   |
   --Session
Method Summary
Session __construct ()
void __destruct ()
void close ()
boolean destroy (string $id)
boolean gc (integer $time_to_live)
void initialize ()
void open ()
string read (string $id)
boolean write (string $id, string $session)
Methods
Constructor __construct (line 125)

Constructor

All of our set up logic for the session in contained here. This object is initially instantiated from pickles.php and the session callbacks are established here. All variables are driven from php.ini and/or the site config. Once configured, the session is started automatically.

  • access: public
Session __construct ()
Destructor __destruct (line 234)

Destructor

Runs garbage collection and closes the session. I'm not sure if the garbage collection should stay as it could be accomplished via php.ini variables. The session_write_close() is present to combat a chicken and egg scenario in earlier versions of PHP 5.

  • access: public
void __destruct ()
close (line 284)

Closes the Session

Same as above, but in reverse.

  • access: public
void close ()
destroy (line 332)

Destroys the Session

Deletes the session from the database.

  • return: whether the query executed correctly
  • access: public
boolean destroy (string $id)
  • string $id: session ID
gc (line 347)

Garbage Collector

This is who you call when you got trash to be taken out.

  • return: whether the query executed correctly
  • access: public
boolean gc (integer $time_to_live)
  • integer $time_to_live: number of seconds a session is active
initialize (line 250)

Initializes the Session

This method exists to combat the fact that calling session_destroy() also clears out the save handler. Upon destorying a session this method is called again so the save handler is all set.

  • access: public
void initialize ()
open (line 272)

Opens the Session

Since the session is in the database, opens the database connection. This step isn't really necessary as the Database object is smart enough to open itself up upon execute.

  • access: public
void open ()
read (line 297)

Reads the Session

Checks the database for the session ID and returns the session data.

  • return: serialized session data
  • access: public
string read (string $id)
  • string $id: session ID
write (line 315)

Writes the Session

When there's changes to the session, writes the data to the database.

  • return: whether the query executed correctly
  • access: public
boolean write (string $id, string $session)
  • string $id: session ID
  • string $session: serialized session data

Documentation generated on Wed, 03 Oct 2012 17:46:06 -0400 by phpDocumentor 1.4.4