Skip to content

Commit f6fd6eb

Browse files
committed
More fixes thanks to reviewers
1 parent 73ff2f0 commit f6fd6eb

File tree

1 file changed

+31
-42
lines changed

1 file changed

+31
-42
lines changed

session/database.rst

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,6 @@ configuration option to tell Symfony to use this service as the session handler:
265265
],
266266
]);
267267
268-
.. caution::
269-
270-
If the session data doesn't fit in the data column, it might get truncated
271-
by the database engine. To make matters worse, when the session data gets
272-
corrupted, PHP ignores the data without giving a warning.
273-
274-
If the application stores large amounts of session data, this problem can
275-
be solved by increasing the column size (use ``BLOB`` or even ``MEDIUMBLOB``).
276-
When using MySQL as the database engine, you can also enable the `strict SQL mode`_
277-
to be notified when such an error happens.
278-
279268
Configuring the Session Table and Column Names
280269
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281270

@@ -335,12 +324,14 @@ These are parameters that you can configure:
335324
The name of the session table in your database;
336325

337326
``db_username``: (default: ``''``)
338-
The username used to connect when using the PDO configuration (it's ignored
339-
when using the connection based on the ``DATABASE_URL`` env var).
327+
The username used to connect when using the PDO configuration (when using
328+
the connection based on the ``DATABASE_URL`` env var, it overrides the
329+
username defined in the env var).
340330

341331
``db_password``: (default: ``''``)
342-
The password used to connect when using the PDO configuration (it's ignored
343-
when using the connection based on the ``DATABASE_URL`` env var).
332+
The password used to connect when using the PDO configuration (when using
333+
the connection based on the ``DATABASE_URL`` env var, it overrides the
334+
password defined in the env var).
344335

345336
``db_id_col`` (default ``sess_id``):
346337
The name of the column where to store the session ID (column type: ``VARCHAR(128)``);
@@ -352,14 +343,22 @@ These are parameters that you can configure:
352343
The name of the column where to store the session creation timestamp (column type: ``INTEGER``);
353344

354345
``db_lifetime_col`` (default ``sess_lifetime``):
355-
The name of the column where to store the session lifetime (column type: ``INTEGER``).
346+
The name of the column where to store the session lifetime (column type: ``INTEGER``);
347+
348+
``db_connection_options`` (default: ``[]``)
349+
An array of driver-specific connection options;
350+
351+
``lock_mode`` (default: ``LOCK_TRANSACTIONAL``)
352+
The strategy for locking the database to avoid *race conditions*. Possible
353+
values are ``LOCK_NONE`` (no locking), ``LOCK_ADVISORY`` (application-level
354+
locking) and ``LOCK_TRANSACTIONAL`` (row-level locking).
356355

357356
Preparing the Database to Store Sessions
358357
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
359358

360359
Before storing sessions in the database, you must create the table that stores
361360
the information. The session handler provides a method called
362-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler::createTable`
361+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\PdoSessionHandler::createTable`
363362
to set up this table for you according to the database engine used::
364363

365364
try {
@@ -388,18 +387,18 @@ MySQL
388387
.. code-block:: sql
389388
390389
CREATE TABLE `sessions` (
391-
`sess_id` VARCHAR(128) NOT NULL PRIMARY KEY,
390+
`sess_id` VARBINARY(128) NOT NULL PRIMARY KEY,
392391
`sess_data` BLOB NOT NULL,
393-
`sess_time` INTEGER UNSIGNED NOT NULL,
394-
`sess_lifetime` MEDIUMINT NOT NULL
392+
`sess_lifetime` MEDIUMINT NOT NULL,
393+
`sess_time` INTEGER UNSIGNED NOT NULL
395394
) COLLATE utf8mb4_bin, ENGINE = InnoDB;
396395
397396
.. note::
398397

399-
A ``BLOB`` column type can only store up to 64 kb. If the data stored in
400-
a user's session exceeds this, an exception may be thrown or their session
401-
will be silently reset. Consider using a ``MEDIUMBLOB`` if you need more
402-
space.
398+
A ``BLOB`` column type (which is the one used by default by ``createTable()``)
399+
stores up to 64 kb. If the user session data exceeds this, an exception may
400+
be thrown or their session will be silently reset. Consider using a ``MEDIUMBLOB``
401+
if you need more space.
403402

404403
PostgreSQL
405404
..........
@@ -409,30 +408,21 @@ PostgreSQL
409408
CREATE TABLE sessions (
410409
sess_id VARCHAR(128) NOT NULL PRIMARY KEY,
411410
sess_data BYTEA NOT NULL,
412-
sess_time INTEGER NOT NULL,
413-
sess_lifetime INTEGER NOT NULL
411+
sess_lifetime INTEGER NOT NULL,
412+
sess_time INTEGER NOT NULL
414413
);
415414
416415
Microsoft SQL Server
417416
....................
418417

419418
.. code-block:: sql
420419
421-
CREATE TABLE [dbo].[sessions](
422-
[sess_id] [nvarchar](255) NOT NULL,
423-
[sess_data] [ntext] NOT NULL,
424-
[sess_time] [int] NOT NULL,
425-
[sess_lifetime] [int] NOT NULL,
426-
PRIMARY KEY CLUSTERED(
427-
[sess_id] ASC
428-
) WITH (
429-
PAD_INDEX = OFF,
430-
STATISTICS_NORECOMPUTE = OFF,
431-
IGNORE_DUP_KEY = OFF,
432-
ALLOW_ROW_LOCKS = ON,
433-
ALLOW_PAGE_LOCKS = ON
434-
) ON [PRIMARY]
435-
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
420+
CREATE TABLE sessions (
421+
sess_id VARCHAR(128) NOT NULL PRIMARY KEY,
422+
sess_data VARBINARY(MAX) NOT NULL,
423+
sess_lifetime INTEGER NOT NULL,
424+
sess_time INTEGER NOT NULL
425+
);
436426
437427
Store Sessions in a NoSQL Database (MongoDB)
438428
--------------------------------------------
@@ -606,6 +596,5 @@ These are parameters that you can configure:
606596
The name of the field where to store the session lifetime.
607597

608598
.. _`phpredis extension`: https://github.com/phpredis/phpredis
609-
.. _`strict SQL mode`: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html
610599
.. _`DoctrineMongoDBBundle configuration`: https://symfony.com/doc/master/bundles/DoctrineMongoDBBundle/config.html
611600
.. _`MongoDB shell`: https://docs.mongodb.com/manual/mongo/

0 commit comments

Comments
 (0)