Skip to content

Added a brief explanation about Doctrine DBAL Session Storage #5019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions cookbook/configuration/pdo_session_storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,85 @@ For MSSQL, the statement might look like the following:
ALLOW_PAGE_LOCKS = ON
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

Doctrine DBAL Session Storage
-----------------------------

Symfony applications can also use a Doctrine DBAL based session storage. This
alternative implementation is very similar to the ``PdoSessionHandler`` explained
above, but uses a Doctrine connection and thus also works with non-PDO-based
drivers like mysqli and OCI8.

The only significant disadvantage of the Doctrine DBAL session storage comparing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that these paragraphs are true for 2.3, but not for 2.6+ (the DBAL session storage has not been migrated to implement session locking yet AFAIK)

it with ``PdoSessionHandler`` is that you can only configure the name of the
table used to store sessions but not its column names.

DBAL Session Storage configuration example:

.. configuration-block::

.. code-block:: yaml

# app/config/config.yml
framework:
session:
# ...
handler_id: session.handler.dbal

parameters:
# ...
dbal_session_table: session

# app/config/services.yml
services:
# ...
session.handler.dbal:
class: Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler
arguments: ["@doctrine.dbal.default_connection", "%dbal_session_table%"]

.. code-block:: xml

<!-- app/config/config.xml -->
<framework:config>
<!-- ... -->
<framework:session handler-id="session.handler.dbal" cookie-lifetime="3600" auto-start="true"/>
</framework:config>

<parameters>
<!-- ... -->
<parameter key="dbal_session_table">session</parameter>
</parameters>

<!-- app/config/services.xml -->
<services>
<!-- ... -->
<service id="session.handler.dbal" class="Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler">
<argument type="service" id="doctrine.dbal.default_connection" />
<argument>%dbal_session_table%</argument>
</service>
</services>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have a complete example:

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:framework="http://symfony.com/schema/dic/symfony"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
        http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

    <framework:config>
        <!-- ... -->
        <framework:session handler-id="session.handler.dbal" />
    </framework:config>

    <parameters>
        <!-- ... -->
        <parameter key="dbal_session_table">session</parameter>
    </parameters>
</container>

<!-- app/config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <!-- ... -->
        <service id="session.handler.dbal" class="Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler">
            <argument type="service" id="doctrine.dbal.default_connection" />
            <argument>%dbal_session_table%</argument>
        </service>
    </services>
</container>


.. code-block:: php

// app/config/config.php
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

$container->loadFromExtension('framework', array(
// ...
'session' => array(
// ...
'handler_id' => 'session.handler.dbal',
),
));

// ...
$container->setParameter('pdo.dbal_session_table', 'sess');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other examples don't have the pdo. prefix.


// app/config/services.php
// ...
$storageDefinition = new Definition('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', array(
new Reference('doctrine.dbal.default_connection'),
'%dbal_session_table%',
));
$container->setDefinition('session.handler.dbal', $storageDefinition);