Last active
January 2, 2016 21:39
-
-
Save jwestbrook/8365101 to your computer and use it in GitHub Desktop.
I had to migrate PHP sessions from file based sessions to Memcached based sessions. I couldn't shutdown the servers involved for the split second it would take because all of my users would lose their current sessions. I put this together to migrate the file based sessions to memcached sessions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$m = new Memcached(); | |
$m->addServer('localhost', 11211); | |
$sessions = scandir("/var/lib/php/session/"); | |
if($sessions) | |
{ | |
foreach($sessions as $s) | |
{ | |
if(!in_array($s,array('.','..'))) | |
{ | |
$session_name = str_replace("sess_","",$s); | |
$session_contents = file_get_contents("/var/lib/php/session/".$s); | |
$m->set("memc.sess.key.".$session_name,$session_contents); | |
print "."; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Few things to change for your environment.