<p>I'm getting the good old session expired popup every minute in the admin panel which is odd given that memcached should be properly configured:</p>
<h3>php.ini</h3>
<pre><code>session.auto_start = 0
session.save_handler=memcached
session.save_path=&quot;mymemcachedhost:11211&quot;
</code></pre>
<h3>config/app.php</h3>
<pre class="lang-php prettyprint-override"><code>return [
    'modules' =&gt; [
        'my-module' =&gt; \modules\Module::class,
    ],
    'components' =&gt; [
        'session' =&gt; [
            'class' =&gt; yii\web\CacheSession::class,
            'as session' =&gt; craft\behaviors\SessionBehavior::class
        ],
       'cache' =&gt; [
           'class' =&gt; yii\caching\MemCache::class,
           'useMemcached' =&gt; true,
           'defaultDuration' =&gt; 86400,
           'servers' =&gt; [
               [
                   'host' =&gt; 'mymemcachedhost',
                   'persistent' =&gt; true,
                   'port' =&gt; 11211,
                   'retryInterval' =&gt; 15,
                   'status' =&gt; true,
                   'timeout' =&gt; 15,
                   'weight' =&gt; 1,
               ],
           ]
        ]
    ]
];
</code></pre>
<h3>/admin/utilities/php-info (craft admin panel)</h3>
<pre><code>session.save_handler    user
session.save_path   mymemcachedhost:11211
</code></pre>
<p>I think the problem might lay with <code>session.save_handler</code> showing up as <code>user</code> in the craft admin panel for the php.ini but if I look at <code>&lt;?php phpinfo(); ?&gt;</code> on either host behind the loadbalancer I see <code>session.save_handler</code> showing up correctly as <code>memcached</code>.</p>
<p>I've verified with <code>telnet</code> and <code>nc</code> that the memcached host responds correctly at the given host:port combo. Any ideas?</p>
<h1>EDIT</h1>
<p>The same problem persists when using redis as a session store:</p>
<h3>redis attempt config/app.php</h3>
<pre><code>&lt;?php
return [
    'components' =&gt; [
        'redis' =&gt; [
            'class' =&gt; yii\redis\Connection::class,
            'port' =&gt; 6379,
            'hostname' =&gt; 'elasticachehostname'
        ],
        'cache' =&gt; [
            'class' =&gt; yii\redis\Cache::class,
            'defaultDuration' =&gt; 86400,
            'keyPrefix' =&gt; 'pm_key',
        ],
        'session' =&gt; [
            'class' =&gt; yii\redis\Session::class,
            'as session' =&gt; craft\behaviors\SessionBehavior::class,
        ],
    ]
];
</code></pre>
<p><code>&quot;yiisoft/yii2-redis&quot;: &quot;2.0&quot;,</code> has been added to composer
With this config I cannot even sign into the admin panel as I get this error in the craft logs (about a dozen times right after another):</p>
<p><code>2019-11-27 14:43:50 [-][5615][-][error][yii\web\Session::open] session_start(): Failed to read session data: user (path: tcp://elasticachehostname:6379)</code></p>
<p>Redis is working in php though as I can run this php file no problem (with properly incrementing numbers:</p>
<pre class="lang-php prettyprint-override"><code>&lt;?php

 ini_set('session.save_handler', 'redis');
 ini_set('session.save_path', 'tcp://elasticachehostname:6379');

session_name('FOOBAR');
session_start();

if (!array_key_exists('visit', $_SESSION)) {
    $_SESSION['visit'] = 0;
}
$_SESSION['visit']++;

echo nl2br(
    'You have been here ' . $_SESSION['visit'] . ' times.'
);
</code></pre>
<p>This would indicate that there is definitely an issue on the craft/yii side of things. I don't know why it cannot connect to it.</p>
<p>I also confirmed it's not a Amazon issue,  I installed redis locally on the host and get the same error message (except of course <code>tcp://localhost...</code>)</p>

CC BY-SA 4.0
2019-11-27T15:21:34.780Z
I tried redis and it must be some issue with AWS. Our staging environment has no issue using memcached or redis for the session but then the prod nodes can't connect to either redis or memcached.... all that despite `nc` succeeding in connecting to the open port of the redis or memcached node...
Max Werner
CC BY-SA 4.0
2019-11-26T20:43:55.377Z
Hrm... not an answer, but we do something similar using Redis for caching and session https://github.com/pixelandtonic/craftnet/blob/master/config/app.php#L90-L103 and https://github.com/pixelandtonic/craftnet/blob/master/config/app.php#L120-L133 Maybe that will give you a lead.
Brad Bell
<craft3><session>
Craft 3 memcached session storage in load balanced environment
# Craft 3 memcached session storage in load balanced environment

(Asked by: username_0 on 2019-11-26)

I'm getting the good old session expired popup every minute in the admin panel which is odd given that memcached should be properly configured:
php.ini
session.auto_start = 0
session.save_handler=memcached
session.save_path="mymemcachedhost:11211"

config/app.php
return [
    'modules' => [
        'my-module' => \modules\Module::class,
    ],
    'components' => [
        'session' => [
            'class' => yii\web\CacheSession::class,
            'as session' => craft\behaviors\SessionBehavior::class
        ],
       'cache' => [
           'class' => yii\caching\MemCache::class,
           'useMemcached' => true,
           'defaultDuration' => 86400,
           'servers' => [
               [
                   'host' => 'mymemcachedhost',
                   'persistent' => true,
                   'port' => 11211,
                   'retryInterval' => 15,
                   'status' => true,
                   'timeout' => 15,
                   'weight' => 1,
               ],
           ]
        ]
    ]
];

/admin/utilities/php-info (craft admin panel)
session.save_handler    user
session.save_path   mymemcachedhost:11211

I think the problem might lay with session.save_handler showing up as user in the craft admin panel for the php.ini but if I look at  on either host behind the loadbalancer I see session.save_handler showing up correctly as memcached.
I've verified with telnet and nc that the memcached host responds correctly at the given host:port combo. Any ideas?
EDIT
The same problem persists when using redis as a session store:
redis attempt config/app.php
 [
        'redis' => [
            'class' => yii\redis\Connection::class,
            'port' => 6379,
            'hostname' => 'elasticachehostname'
        ],
        'cache' => [
            'class' => yii\redis\Cache::class,
            'defaultDuration' => 86400,
            'keyPrefix' => 'pm_key',
        ],
        'session' => [
            'class' => yii\redis\Session::class,
            'as session' => craft\behaviors\SessionBehavior::class,
        ],
    ]
];

"yiisoft/yii2-redis": "2.0", has been added to composer
With this config I cannot even sign into the admin panel as I get this error in the craft logs (about a dozen times right after another):
2019-11-27 14:43:50 [-][5615][-][error][yii\web\Session::open] session_start(): Failed to read session data: user (path: tcp://elasticachehostname:6379)
Redis is working in php though as I can run this php file no problem (with properly incrementing numbers:

This would indicate that there is definitely an issue on the craft/yii side of things. I don't know why it cannot connect to it.
I also confirmed it's not a Amazon issue,  I installed redis locally on the host and get the same error message (except of course tcp://localhost...)

**Tags:** craft3, session
> **Comments:**
> **username_1**: Hrm... not an answer, but we do something similar using Redis for caching and session https://github.com/pixelandtonic/craftnet/blob/master/config/app.php#L90-L103 and https://github.com/pixelandtonic/craftnet/blob/master/config/app.php#L120-L133 Maybe that will give you a lead.  
> **username_0**: I tried redis and it must be some issue with AWS. Our staging environment has no issue using memcached or redis for the session but then the prod nodes can't connect to either redis or memcached.... all that despite `nc` succeeding in connecting to the open port of the redis or memcached node...  

---

## 0 answers

