1

For my Symfony2 project, i'm using the session storage in a database.

So, i configure my config.yml like that :

framework:
    session:
        handler_id:     session.handler.pdo

parameters:
    pdo.db_options:
        db_table:    session
        db_id_col:   session_id
        db_data_col: session_value
        db_time_col: session_time

services:
    pdo:
        class: PDO
        arguments:
            - "pgsql:host=%database_host%;dbname=%database_name%"
            - "%database_user%"
            - "%database_password%"
        calls:
            - [setAttribute, [3, 2]]

    session.handler.pdo:
        class:     Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
        arguments: ["@pdo", "%pdo.db_options%"]

When i login with an account, a new ligne is created in my session table, normal. But when i display a page of my website with nothing (just the index for example), a new line is created too.

So, with 4-5 members, i already have +80 lines of sessions in table...

How can i do that ? I only need a line when a member login.

1 Answer 1

2

You get a new line each time an user comes to your app without any cookie. By default, the cookie is a session cookie, which means it is destroyed by your browser when you close it.

But the line in your DB doesn't get deleted, because your server has no mean to know that.

So here comes the garbage collector... There is a small chance, for each request, that the server will cleanup old sessions (older than session.max_lifetime). But on Debian-like systems, the probability is set to zero, because there's a cron task taking care of it (see https://github.com/symfony/symfony/issues/10349)

So you might need to explicitly set the session.gc_probability to one :

http://symfony.com/doc/current/components/http_foundation/session_configuration.html#configuring-garbage-collection

Sign up to request clarification or add additional context in comments.

2 Comments

Euh, i need to add session.gc_probability = 1 in my php.ini ?
You can do that, or configure it at the application level, using in your config.yml under framework session gc_probability: 1 `

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.