CDbHttpSession
CDbHttpSession extends
CHttpSession by using database as session data storage.
CDbHttpSession stores session data in a DB table named 'YiiSession'. The table name
can be changed by setting
sessionTableName. If the table does not exist,
it will be automatically created if
autoCreateSessionTable is set true.
The following is the table structure:
CREATE TABLE YiiSession
(
id CHAR(32) PRIMARY KEY,
expire INTEGER,
data TEXT
)
CDbHttpSession relies on
PDO to access database.
By default, it will use an SQLite3 database named 'session-YiiVersion.db' under the application runtime directory.
You can also specify
connectionID so that it makes use of a DB application component to access database.
When using CDbHttpSession in a production server, we recommend you pre-create the session DB table
and set
autoCreateSessionTable to be false. This will greatly improve the performance.
You may also create a DB index for the 'expire' column in the session table to further improve the performance.
Property Details
public boolean $autoCreateSessionTable;
whether the session DB table should be automatically created if not exists. Defaults to true.
public string $connectionID;
the ID of a CDbConnection application component. If not set, a SQLite database
will be automatically created and used. The SQLite database file is
is protected/runtime/session-YiiVersion.db.
the DB connection instance
public string $sessionTableName;
the name of the DB table to store session content.
Note, if autoCreateSessionTable is false and you want to create the DB table manually by yourself,
you need to make sure the DB table is of the following structure:
(id CHAR(32) PRIMARY KEY, expire INTEGER, data TEXT)
Returns a value indicating whether to use custom session storage.
This method overrides the parent implementation and always returns true.
Method Details
protected void createSessionTable( CDbConnection $db, string $tableName)
|
| $db |
CDbConnection |
the database connection |
| $tableName |
string |
the name of the table to be created |
Creates the session DB table.
|
public boolean destroySession(string $id)
|
| $id |
string |
session ID |
| {return} |
boolean |
whether session is destroyed successfully |
Session destroy handler.
Do not call this method directly.
|
public boolean gcSession(integer $maxLifetime)
|
| $maxLifetime |
integer |
the number of seconds after which data will be seen as 'garbage' and cleaned up. |
| {return} |
boolean |
whether session is GCed successfully |
Session GC (garbage collection) handler.
Do not call this method directly.
|
public boolean getUseCustomStorage()
|
| {return} |
boolean |
whether to use custom storage. |
Returns a value indicating whether to use custom session storage.
This method overrides the parent implementation and always returns true.
|
public boolean openSession(string $savePath, string $sessionName)
|
| $savePath |
string |
session save path |
| $sessionName |
string |
session name |
| {return} |
boolean |
whether session is opened successfully |
Session open handler.
Do not call this method directly.
|
public string readSession(string $id)
|
| $id |
string |
session ID |
| {return} |
string |
the session data |
Session read handler.
Do not call this method directly.
|
public boolean writeSession(string $id, string $data)
|
| $id |
string |
session ID |
| $data |
string |
session data |
| {return} |
boolean |
whether session write is successful |
Session write handler.
Do not call this method directly.