8

If you open the front end with multiple tabs in the browser, the following error is output:.

Exception #0 (Exception): Warning: session_start(): Failed to read session data: user (path: /var/opt/remi/php71/lib/php/session) in /var/www/html/primary/vendor/magento/framework/Session/SessionManager.php on line 189

The www.conf file specifies the location of the session as follows:.

php_value[session.save_path]    = /var/opt/remi/php71/lib/php/session

The permissions for saving sessions are set as follows:.

total 0
drwxr-xr-x 5 www-data www-data 53 May 14 20:17 .
drwxr-xr-x 7 root     root     71 May 14 20:06 ..
drwxrwx--- 2 www-data www-data  6 May  1 18:33 opcache
drwxrwx--- 2 www-data www-data  6 May  1 18:33 session
drwxrwx--- 2 www-data www-data  6 May  1 18:33 wsdlcache

The configuration problem is complete, but an exception message is printed. Please tell me how to fix it.

Additional information. I also set up Redis. The settings are as follows:.

'session' => [
        'save' => 'redis',
        'redis' => [
            'host' => '127.0.0.1',
            'port' => '6381',
            'password' => '',
            'timeout' => '2.5',
            'persistent_identifier' => '',
            'database' => '2',
            'compression_threshold' => '2048',
            'compression_library' => 'gzip',
            'log_level' => '3',
            'max_concurrency' => '6',
            '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'
        ]
    ],
9
  • 3
    did you try changing max_concurrency? Seems like that is your issue if you are opening multiple tabs
    – Anthony
    May 17, 2019 at 5:56
  • The initial value was set to "max _ concurrency = 6". What number should I set? May 17, 2019 at 6:18
  • i think the rough rule is 10% of your total php processes. I personally have mine set at 15
    – Anthony
    May 17, 2019 at 6:21
  • Change settings and validate. If not, add a comment. At that time, I would be happy if you could answer my message. May 17, 2019 at 6:24
  • Sorry, i am not sure what you mean?
    – Anthony
    May 17, 2019 at 6:28

3 Answers 3

12

Adding an answer for posterity as this was already correctly resolved in the comments by Anthony.

When using Redis to store the session data, the Warning: session_start(): Failed to read session data error can be fixed by increasing the max_concurrency value.

4
  • Unfortunately this did not resolve my problem :( still facing issues even after increasing max_concurrency value Nov 25, 2019 at 8:50
  • Thanks marina and Anthony this worked for me. Oct 9, 2020 at 13:00
  • @AhsanHorani, then maybe you did not increased it enough.
    – Black
    Jan 28, 2021 at 8:32
  • Thank you it helped. I increased this parameter from 6 to 25 in the env.php file Mar 30, 2021 at 16:20
8

This issue can fixed by increase max_concurrency.

It will relate to your traffic and server conditions. In my case i'm able to solved this problem by increase max_concurrency from 6 to 24

This is all happening because of contention for accessing session data from single threaded Redis. The max_concurency config value defines the size of the queue that can form to access Redis and retrieve the session. In the event of lots of traffic hitting the server at once, some users will receive this behavior because the queue is full, so the request to access the Redis session back-end is denied. PHP session handling kicks in here and if configured correctly will start creating sessions (this is still an issue as Redis is meant to be doing this for a reason, PHP will be saving to local disk so sessions wont be available across multiple web servers etc).

This same error will happen also on the front-end of Magento2. Try it by opening 10 or more tabs of different pages; clear the FPC (or just disable full page cache to emulate hitting un-cached pages); reload all the tabs at once as above and again some will fail. This is particularly bad when you have items in your cart as the local storage is not synched, resulting in the "I have no items in my cart, but there are items in my mini-cart" scenario I'm sure you've come across.

1

There is also a Magento issue about this error and a PR allready created. I hope we get the fix with the next release.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.