Class PdoSessionHandler
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.
- Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler implements SessionHandlerInterface
Author: Fabien Potencier <fabien@symfony.com>
Author: Michael Williams <michael.williams@funsational.com>
Author: Tobias Schultze <http://tobion.de>
See: http://php.net/sessionhandlerinterface
Located at Storage/Handler/PdoSessionHandler.php
public
|
|
public
|
|
public
boolean
|
#
isSessionExpired( )
Returns true when the current session exists but expired according to session.gc_maxlifetime. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
protected
|
integer |
LOCK_NONE
|
0 |
#
No locking is done. This means sessions are prone to loss of data due to race conditions of concurrent requests to the same session. The last session write will win in this case. It might be useful when you implement your own logic to deal with this like an optimistic approach. |
integer |
LOCK_ADVISORY
|
1 |
#
Creates an application-level lock on a session. The disadvantage is that the lock is not enforced by the database and thus other, unaware parts of the application could still concurrently modify the session. The advantage is it does not require a transaction. This mode is not available for SQLite and not yet implemented for oci and sqlsrv. |
integer |
LOCK_TRANSACTIONAL
|
2 |
#
Issues a real row lock. Since it uses a transaction between opening and closing a session, you have to be careful when you use same database connection that you also use for your application logic. This mode is the default because it's the only reliable solution across DBMSs. |