[ Index ]

PHP Cross Reference of phpBB-3.3.2-deutsch




/vendor/symfony/http-foundation/Session/Storage/Handler/ -> PdoSessionHandler.php (summary)

(no description)

File Size: 918 lines (37 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

PdoSessionHandler:: (23 methods):

Class: PdoSessionHandler  - X-Ref

Session handler using a PDO connection to read and write data.

It works with MySQL, PostgreSQL, Oracle, SQL Server and SQLite and implements
different locking strategies to handle concurrent access to the same session.
Locking is necessary to prevent loss of data due to race conditions and to keep
the session data consistent between read() and write(). With locking, requests
for the same session will wait until the other one finished writing. For this
reason it's best practice to close a session as early as possible to improve
concurrency. PHPs internal files session handler also implements locking.

Attention: Since SQLite does not support row level locks but locks the whole database,
it means only one session can be accessed at a time. Even different sessions would wait
for another to finish. So saving session in SQLite should only be considered for
development or prototypes.

Session data is a binary string that can contain non-printable characters like the null byte.
For this reason it must be saved in a binary column in the database like BLOB in MySQL.
Saving it in a character column could corrupt the data. You can use createTable()
to initialize a correctly defined table.

__construct($pdoOrDsn = null, array $options = [])   X-Ref
You can either pass an existing database connection as PDO instance or
pass a DSN string that will be used to lazy-connect to the database
when the session is actually used. Furthermore it's possible to pass null
which will then use the session.save_path ini setting as PDO DSN parameter.

List of available options:
* db_table: The name of the table [default: sessions]
* db_id_col: The column where to store the session id [default: sess_id]
* db_data_col: The column where to store the session data [default: sess_data]
* db_lifetime_col: The column where to store the lifetime [default: sess_lifetime]
* db_time_col: The column where to store the timestamp [default: sess_time]
* db_username: The username when lazy-connect [default: '']
* db_password: The password when lazy-connect [default: '']
* db_connection_options: An array of driver-specific connection options [default: []]
* lock_mode: The strategy for locking, see constants [default: LOCK_TRANSACTIONAL]

param: \PDO|string|null $pdoOrDsn A \PDO instance or DSN string or URL string or null
param: array            $options  An associative array of options

createTable()   X-Ref
Creates the table to store sessions which can be called once for setup.

Session ID is saved in a column of maximum length 128 because that is enough even
for a 512 bit configured session.hash_function like Whirlpool. Session data is
saved in a BLOB. One could also use a shorter inlined varbinary column
if one was sure the data fits into it.

isSessionExpired()   X-Ref
Returns true when the current session exists but expired according to session.gc_maxlifetime.

Can be used to distinguish between a new session and one that expired due to inactivity.

return: bool Whether current session expired

open($savePath, $sessionName)   X-Ref

read($sessionId)   X-Ref

gc($maxlifetime)   X-Ref

return: bool

doDestroy($sessionId)   X-Ref

doWrite($sessionId, $data)   X-Ref

updateTimestamp($sessionId, $data)   X-Ref

close()   X-Ref

connect($dsn)   X-Ref
Lazy-connects to the database.

param: string $dsn DSN string

buildDsnFromUrl($dsnOrUrl)   X-Ref
Builds a PDO DSN from a URL-like connection string.

param: string $dsnOrUrl
return: string

beginTransaction()   X-Ref
Helper method to begin a transaction.

Since SQLite does not support row level locks, we have to acquire a reserved lock
on the database immediately. Because of https://bugs.php.net/42766 we have to create
such a transaction manually which also means we cannot use PDO::commit or
PDO::rollback or PDO::inTransaction for SQLite.

Also MySQLs default isolation, REPEATABLE READ, causes deadlock for different sessions
due to https://percona.com/blog/2013/12/12/one-more-innodb-gap-lock-to-avoid/ .
So we change it to READ COMMITTED.

commit()   X-Ref
Helper method to commit a transaction.

rollback()   X-Ref
Helper method to rollback a transaction.

doRead($sessionId)   X-Ref
Reads the session data in respect to the different locking strategies.

We need to make sure we do not return session data that is already considered garbage according
to the session.gc_maxlifetime setting because gc() is called after read() and only sometimes.

param: string $sessionId Session ID
return: string The session data

doAdvisoryLock($sessionId)   X-Ref
Executes an application-level lock on the database.

param: string $sessionId Session ID
return: \PDOStatement The statement that needs to be executed later to release the lock

convertStringToInt($string)   X-Ref
Encodes the first 4 (when PHP_INT_SIZE == 4) or 8 characters of the string as an integer.

Keep in mind, PHP integers are signed.

param: string $string
return: int

getSelectSql()   X-Ref
Return a locking or nonlocking SQL query to read session information.

return: string The SQL string

getInsertStatement($sessionId, $sessionData, $maxlifetime)   X-Ref
Returns an insert statement supported by the database for writing session data.

param: string $sessionId   Session ID
param: string $sessionData Encoded session data
param: int    $maxlifetime session.gc_maxlifetime
return: \PDOStatement The insert statement

getUpdateStatement($sessionId, $sessionData, $maxlifetime)   X-Ref
Returns an update statement supported by the database for writing session data.

param: string $sessionId   Session ID
param: string $sessionData Encoded session data
param: int    $maxlifetime session.gc_maxlifetime
return: \PDOStatement The update statement

getMergeStatement($sessionId, $data, $maxlifetime)   X-Ref
Returns a merge/upsert (i.e. insert or update) statement when supported by the database for writing session data.

param: string $sessionId   Session ID
param: string $data        Encoded session data
param: int    $maxlifetime session.gc_maxlifetime
return: \PDOStatement|null The merge statement or null when not supported

getConnection()   X-Ref
Return a PDO instance.

return: \PDO

Generated: Wed Nov 11 20:28:18 2020 Cross-referenced by PHPXref 0.7.1