Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is no out-of-the-box solution available right now for what you are asking, but writing a custom script for this task can actually be fairly simple. </p> <p>Esentially, phpredis stores session data in redis as strings with the following key name format: <code>PHPREDIS_SESSION:$sessionid</code>, where <code>$sessionid</code> is the php id of the session, the one retrievable via <code>session_id()</code>. The session data is "encoded" as a php-session serialized variable (which is a slightly different format to the common php serialize/unserialize, see <a href="http://php.net/manual/en/function.session-encode.php" rel="nofollow">session_encode</a>). </p> <p>Now that we know this, there are two possibilities to migrate session data stored in files:</p> <ul> <li><p>Iterate through every session file (the actual path is set at <code>session.save_path</code> in your php.ini), read the data and write it back to redis. The files themselves store the php-session serialized representation of the session data, which means the content can be copied as it is directly to redis, and the filenames have the following pattern: <code>sess_$sessionid</code>, where $sessionid is, you guessed it, the id you'll want to use for your redis keys.</p></li> <li><p>Migrate the data progressively by staying with file based sessions for now, but populating redis in real time as session data is being used, until the amount of sessions stored in redis looks good enough to do the switch. This could be achieved by doing something like:</p> <p><code>$redis-&gt;set("PHPREDIS_SESSION:".session_id(), session_encode());</code></p> <p>Right before each script ends. This method may add a little bit of overhead depending on the amount of data in session and how session_encode works.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload