@@ -265,17 +265,6 @@ configuration option to tell Symfony to use this service as the session handler:
265
265
],
266
266
]);
267
267
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
-
279
268
Configuring the Session Table and Column Names
280
269
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281
270
@@ -335,12 +324,14 @@ These are parameters that you can configure:
335
324
The name of the session table in your database;
336
325
337
326
``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).
340
330
341
331
``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).
344
335
345
336
``db_id_col `` (default ``sess_id ``):
346
337
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:
352
343
The name of the column where to store the session creation timestamp (column type: ``INTEGER ``);
353
344
354
345
``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).
356
355
357
356
Preparing the Database to Store Sessions
358
357
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
359
358
360
359
Before storing sessions in the database, you must create the table that stores
361
360
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 `
363
362
to set up this table for you according to the database engine used::
364
363
365
364
try {
@@ -388,18 +387,18 @@ MySQL
388
387
.. code-block :: sql
389
388
390
389
CREATE TABLE `sessions` (
391
- `sess_id` VARCHAR (128) NOT NULL PRIMARY KEY,
390
+ `sess_id` VARBINARY (128) NOT NULL PRIMARY KEY,
392
391
`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
395
394
) COLLATE utf8mb4_bin, ENGINE = InnoDB;
396
395
397
396
.. note ::
398
397
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.
403
402
404
403
PostgreSQL
405
404
..........
@@ -409,30 +408,21 @@ PostgreSQL
409
408
CREATE TABLE sessions (
410
409
sess_id VARCHAR(128) NOT NULL PRIMARY KEY,
411
410
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
414
413
);
415
414
416
415
Microsoft SQL Server
417
416
....................
418
417
419
418
.. code-block :: sql
420
419
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
+ );
436
426
437
427
Store Sessions in a NoSQL Database (MongoDB)
438
428
--------------------------------------------
@@ -606,6 +596,5 @@ These are parameters that you can configure:
606
596
The name of the field where to store the session lifetime.
607
597
608
598
.. _`phpredis extension` : https://github.com/phpredis/phpredis
609
- .. _`strict SQL mode` : https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html
610
599
.. _`DoctrineMongoDBBundle configuration` : https://symfony.com/doc/master/bundles/DoctrineMongoDBBundle/config.html
611
- .. _`MongoDB shell` : http ://docs.mongodb.org/v2.2/tutorial/getting-started-with-the-mongo-shell/
600
+ .. _`MongoDB shell` : https ://docs.mongodb.org/v2.2/tutorial/getting-started-with-the-mongo-shell/
0 commit comments