Saturday, August 24, 2013

Load Balancing Issue with Symfony2 and Session

I am going to explain the problem with symfony2 and a load balancing scenario.

If  you are using Round Robin load balancing technique for symfony2 application, your session storage must be database driven.

Below is the configuration for database driven session storage in symfony2 application:

# app/config/config.yml
framework:
    session:
        storage_id: session.storage.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:
            dsn:      "mysql:dbname=mydatabase"
            user:     myuser
            password: mypassword

    session.storage.pdo:
        class: Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage
        arguments: ["@pdo", "%session.storage.options%", "%pdo.db_options%"]


Here is the reference article about this: How to use PdoSessionStorage to store Sessions in the Database