Skip to content

Commit c9f3850

Browse files
committed
feature #5516 Added a note about session data size in PdoSessionHandler (javiereguiluz)
This PR was squashed before being merged into the 2.3 branch (closes #5516). Discussion ---------- Added a note about session data size in PdoSessionHandler | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to | all | Fixed tickets | #5269 Commits ------- a52b159 Added a note about session data size in PdoSessionHandler
2 parents 81fc69a + a52b159 commit c9f3850

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

cookbook/configuration/pdo_session_storage.rst

+22-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ How to Use PdoSessionHandler to Store Sessions in the Database
77
The default Symfony session storage writes the session information to files.
88
Most medium to large websites use a database to store the session values
99
instead of files, because databases are easier to use and scale in a
10-
multi webserver environment.
10+
multiple web server environment.
1111

1212
Symfony has a built-in solution for database session storage called
1313
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`.
@@ -172,15 +172,18 @@ of your project's data, you can use the connection settings from the
172172
'%database_password%',
173173
));
174174
175-
Example SQL Statements
176-
----------------------
175+
.. _example-sql-statements:
176+
177+
Preparing the Database to Store Sessions
178+
----------------------------------------
179+
180+
Before storing sessions in the database, you must create the table that stores
181+
the information. The following sections contain some examples of the SQL statements
182+
you may use for your specific database engine.
177183

178184
MySQL
179185
~~~~~
180186

181-
The SQL statement for creating the needed database table might look like the
182-
following (MySQL):
183-
184187
.. code-block:: sql
185188
186189
CREATE TABLE `session` (
@@ -193,8 +196,6 @@ following (MySQL):
193196
PostgreSQL
194197
~~~~~~~~~~
195198

196-
For PostgreSQL, the statement should look like this:
197-
198199
.. code-block:: sql
199200
200201
CREATE TABLE session (
@@ -207,8 +208,6 @@ For PostgreSQL, the statement should look like this:
207208
Microsoft SQL Server
208209
~~~~~~~~~~~~~~~~~~~~
209210

210-
For MSSQL, the statement might look like the following:
211-
212211
.. code-block:: sql
213212
214213
CREATE TABLE [dbo].[session](
@@ -225,3 +224,16 @@ For MSSQL, the statement might look like the following:
225224
ALLOW_PAGE_LOCKS = ON
226225
) ON [PRIMARY]
227226
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
227+
228+
.. note::
229+
230+
If the session data doesn't fit in the data column, it might get truncated
231+
by the database engine. To make matters worse, when the session data gets
232+
corrupted, PHP ignores the data without giving a warning.
233+
234+
If the application stores large amounts of session data, this problem can
235+
be solved by increasing the column size (use ``BLOB`` or even ``MEDIUMBLOB``).
236+
When using MySQL as the database engine, you can also enable the `strict SQL mode`_
237+
to get noticed when such an error happens.
238+
239+
.. _`strict SQL mode`: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html

0 commit comments

Comments
 (0)