Created
December 4, 2014 17:25
-
-
Save apinstein/92865ce7d479b50a2726 to your computer and use it in GitHub Desktop.
migrate php file sessions to dynamo
This file contains 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 | |
require 'conf/webapp.conf'; | |
$sessionTableName = ''; | |
$sessionLifetime = ini_get('session.gc_maxlifetime'); | |
$sdir = '/opt/www/domains/tourbuzz/runtime/sessions'; // hard-code so it still works after switching live to dynamo | |
$awsKey = ''; | |
$awsSecretKey = ''; | |
$dynamo = new AmazonDynamoDB(array( | |
'key' => $awsKey, | |
'secret' => $awsSecretKey | |
)); | |
foreach (glob("{$sdir}/*") as $i) { | |
// session file: sess_23c5e69a7acb1532afd02df87926987e | |
list(,$sessionId) = explode('_', basename($i)); | |
$sessionData = file_get_contents($i); | |
print "[{$sessionId}] {$sessionData}" . PHP_EOL; | |
$response = $dynamo->put_item(array( | |
'TableName' => $sessionTableName, | |
'Item' => $dynamo->attributes(array( | |
'id' => "PHPSESSID_{$sessionId}", // PHPSESSID_dmvfqvvlg2he2n5v2981ek5f95 | |
'expires' => time() + $sessionLifetime, | |
'data' => $sessionData, | |
)), | |
)); | |
if (!$response->isOK()) | |
{ | |
print "[{$sessionId}] ERROR" . PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment