Use session_regenerate_id in Magento 2 with PHP 7

magento2memcachedphp-7session

I've got an install of Magento 2.0 running on Centos 6.7 with PHP 7. I'm using Redis for cache and Memcached for session data. Everything so far on the frontend works great, but I'm getting the following error when I try to log into the backend.

Recoverable Error: session_regenerate_id(): Failed to create(read) session ID: user (path: 127.0.0.1:11211)

I did some research on Google and found posts on Github from both Inchoo and colinmollenhour that say that the issue is that the session data that's being returned can sometimes be the boolean false instead of a string. From what I can gather PHP 5 was fine with getting the boolean false whereas PHP 7 must have a string returned. So their solution was to cast the session data variable as a string. The problem for me is that their solution is for Magento 1.x and I'm working with Magento 2.

So I did some more research/code diving and the closest thing I could find was in vendor/magento/framework/Session/SaveHandler/DbTable.php where in the read() function I cast the returned $data variable as a string. Didn't work although I don't think that's the right spot. So does anyone know where the read() function for reading session data when using Memcached is at and/or how to fix this particular issue in Magento 2?

Best Answer

I'm having the same issue when I upgraded my stack to PHP 7 to do some M2 performance testing.

The temporary fix is in the SaveHandler.php file: /vendor/magento/framework/Session/SaveHandler.php

Cast the return value for the read function and you'll be good to go.

Here's the issue I logged on M2's github page: https://github.com/magento/magento2/issues/2827

Related Topic