where session files save – Magento2 Handling Session

where session files save – Magento2 Handling Session

In this post we will show you where session files save – Magento2 Handling Session, hear for where session files save – Magento2 Handling Session we will give you demo and example for implement.

This post will explain about the session files where it will save in Magento2.

  1. File Based Session Storage
  2. Maintain Session using Redis Cache
  3. Maintain Session using Memcache
  4. Maintain Session from Database
    1. 1. File Based Session Storage ::

      This is default session storage in Magento. We can maintain the session as a file from the specific folder path. We have to specify the session type & file path from following file root/app/env.php.
      Example:

      'session' =>
         array (
           'save' => 'files',
           'save_path' => '<FILE FOLDER PATH>',
      )
      

      We can also find where session path is configured in php from ini file. Open php.ini and check session.save_path. In this variable folder path will be defined. Default path is /var/lib/php/sessions.

      2. Maintain Session using Redis Cache ::

      Session’s are stored in Redis server. We can also configure the Redis cache from root/app/env.php file in Magento2.

      Example:
      Below is sample code to configure the redis cache. Here i declared only few main variables. But Yes we can also configure necessary variables. For more info please rever wiki or Magento Dev Tutorial

      'session' =>
      array (
        'save' => 'redis',
        'redis' =>
        array (
          'host' => '<HOST>',
          'port' => '<REDIS SERVER PORT>',
          'password' => '<PASSWORD>',
        )
      ),
      

      3. Maintain Session using Menarche ::

      Session’s are stored in RAM. We can also configure the Menarche cache from root/app/env.php. file in Magento2.
      Example:

      'session' =>
         array (
            'save' => 'memcached',
            'save_path' => '<MEMCACHEHOST>:<MEMCACHEPORT>'
      ),
      

      4. Maintain Session from Database ::

      Storing the session in Database is fine. We can verify the session whenever we need it. But as per over team understanding Using Database is little tricky to handle the Database server.

      Because each and every time database transaction will happen due to this there might be getting a database slow. It may affect the performance of the website.

      Hope this code and post will helped you for implement where session files save – Magento2 Handling Session. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

1 thought on “where session files save – Magento2 Handling Session”

  1. Starlyn kpoptickets

    hi i have been reading all over but nothing with details just generic information.

    I setup a load balancer with auto scaling and aurora DB. then after a couple of servers appeared during the test the site sucessfully stayed online, however users cant add anything to the cart or even stay logged. so I created a redis cluster and updated the env like this:

    ‘session’ => [
    ‘save’ => ‘files’,
    ‘redis’ => [
    ‘host’ => ‘redis cluster entry point ‘,
    ‘port’=>’6379’,
    ‘database’ => ‘2’,
    ‘password’ => ”,
    ‘timeout’ => ‘2.5’,
    ‘persistent_identifier’ => ”,
    ‘database’ => ‘2’,
    ‘compression_threshold’ => ‘2048’,
    ‘compression_library’ => ‘gzip’,
    ‘log_level’ => ‘1’,
    ‘max_concurrency’ => ’20’,
    ‘break_after_frontend’ => ‘5’,
    ‘break_after_adminhtml’ => ’30’,
    ‘first_lifetime’ => ‘600’,
    ‘bot_first_lifetime’ => ’60’,
    ‘bot_lifetime’ => ‘7200’,
    ‘disable_locking’ => ‘0’,
    ‘min_lifetime’ => ’60’,
    ‘max_lifetime’ => ‘2592000’
    ]
    ],

    ‘cache’ => [
    ‘frontend’ => [
    ‘default’ => [
    ‘id_prefix’ => ’40d_’,
    ‘backend’ => ‘Cm_Cache_Backend_Redis’,
    ‘backend_options’ => [
    ‘server’ => ‘127.0.0.1’,
    ‘database’ => ‘0’,
    ‘port’ => ‘6379’,
    ‘password’ => ‘xxx’,
    ‘compress_data’ => ‘1’,
    ‘compression_lib’ => ”
    ]
    ],
    ‘page_cache’ => [
    ‘id_prefix’ => ’40d_’,
    ‘backend’ => ‘Cm_Cache_Backend_Redis’,
    ‘backend_options’ => [
    ‘server’ => ‘127.0.0.1’,
    ‘database’ => ‘1’,
    ‘port’ => ‘6379’,
    ‘password’ => ‘xxx’,
    ‘compress_data’ => ‘0’,
    ‘compression_lib’ => ”
    ]
    ]
    ]
    ],

    the site stayed working without errors so I recreated this server as the launch template for the scaling group. did the test with 4 servers all with the same env config. same problem: users cart gets emptied and cant login and I cant login as admin either.

    What am I missing? do we use the cluster entry point as host or do we use the node end point? can I leave the page cache in local redis or they need to be pointed to a cluster? how can I point them? all the guides I find all use local server 🙁

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  13  =  16

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US