Yii1 & Yii2 issue with PHP 7.3 and memcache

Hi,

we have a couple of projects running on Yii1 and on Yii2 currently using lamp environment on php 7.2 plus memcache (2 memcache servers).
All apps are configured so that sessions are stored in cache, that is memcache.

On local environment (Windows host OS) we use Wamp on php 7.2 also with local memcached server (single memcache server).
We are at the process of upgrading to PHP 7.3 however, the very first step of our upgrade, the local environment, has broken.

To be more specific, since upgrading to PHP 7.3 none of the applications (either Yii1 or Yii2) seem to be consistent regarding maintaining sessions (keeping user logged in).
After a user has logged in, without using remember-me option and cookie validation, at completely random timings while refreshing the page, get’s logged out. This may be on the very next refresh or after 20 attempts, it is completely random and if you keep refreshing the page you notice that it may recover again the session at sometimes, stating that user is logged in and then losing it again.

I ve opened an issue over here
https://github.com/nono303/PHP7-memcache-dll/issues/16 since at the begining i thought it might have been a memcache issue, and later here
https://github.com/websupport-sk/pecl-memcache/issues/58
however, after various tests, it seems quite possible that the issue lies somewhere on Yii and not on memcache.

Runing a plain php script to test memcache (not using Yii)

$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
$get_result = $memcache->get('key');
echo "Data from the cache:\n";
var_dump($get_result);exit;

Configuration seems like the following (pasting from a Yii1, similar on Yii2)

'session' => array(
    'class' => 'CCacheHttpSession',
    'cacheID' => 'cache',
    'timeout' => 600,
    'cookieParams' => [
      'lifetime' => 600,
      // 'secure' => true,
      'httpOnly' => true,
    ],
),
'cache' => array(
    'class' => 'CMemCache',
    'servers' => array(
        array(
            'host' => 'localhost',
            'port' => 11211,
        ),
    ),
),

What Yii version do you have? 1.1.18 fixed PHP 7 related bug in CCacheHttpSession when destroying not cached sessions.

I have this issue present on projects running Yii 1.1.20 / 1.1.21 and Yii 2.0.28

edit :
It is likely the insident to appear outside Yii as well. However, it seems that storing a very small value in cache (outside Yii) makes it quite harder and rarer to be lost among refreshes, so that it can’t be easily noticed.

If it’s both then it’s definitely something in the memcache build you have. There are multiple ways solving that:

  1. Finding/fixing the root cause.
  2. Using memcached for linux via Docker container.
  3. Switching to Redis (it’s fine as cache).

Thank you for your reply, i ve spend the few past days searching what might be causing the issue, with no result. As i previously said, there is some slight inidcation that is happening outside yii as well, but since i can’t reproduce it in a specific way, i m not so sure about it.
I thought of using Redis, but this will end up having different environment on my local machine and diffrent on staging / production server, so i won’t be able to spot a workaround if the same issue applies on staging / production server as well.

Does your staging/production run Windows? If it’s a Linux, using docker-based memcached could be a good idea.

It’s a Linux environment, i guess i might need to move over docker.

I listened to your advice, and now testing with docker. However, since being new to it, and despite the struggle to get one of the apps running, I still have some questions that haven’t been able to answer even from stackoverflow, and docker community.
Is it ok to start a thread over here with some docker related questions regarding your day to day experience and issue handling working on your yii apps?

Yes. It’s fine but it’s better to be not a single thread but multiple ones focused on concrete topics.