I want transfer magento session storage from database to files.

I want to know how to do this.

What i did is, download [BLOB - 3.6 KiB] file from database core_session table for session and rename it with sess_frontend_session_id like sess_n7g9t1872co23p0btnbos921c4

and then upload file to var/session but it's not working

Cart data is lost for not logged in customers.


1 Answer 1


Finally find the solution to transfer session data from database to files

You can run following script to transfer session data from database to files

ini_set('memory_limit', '500M');
ini_set('max_execution_time', 0);
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
require_once 'app/Mage.php';

    $resource = Mage::getSingleton('core/resource');

    $readConnection = $resource->getConnection('core_read');

    $table = $resource->getTableName('core/session');

    $query = 'SELECT * FROM ' . $table;

    $session = $readConnection->fetchAll($query);

    $filePath = 'var/session/';
    foreach ($session as $sess) {
        $file = $filePath.'sess_'.$sess['session_id'];
        $fp = fopen($file, 'w');
        fwrite($fp, $sess['session_data']);
        chmod($file, 0777);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.