I started with adding the following to the original code of Mage_Core_Model_Session_Abstract_Varien
Mage::log(
sprintf(
'useValidateSessionExpire fail "%s" "%d" "%d" "%s" "%s" "%s"',
print_r($sessionData[self::VALIDATOR_SESSION_EXPIRE_TIMESTAMP], 1),
time(),
$this->_time,
get_class($this),
session_name(),
session_id()
),
Zend_Log::DEBUG,
'session-validation.log',
true
);
it gave me a good insight about affected classes and their correlation and how much session were expired. But that was not explaining why it happens and which user actions lead to the problem.
I decided to build a small PHP script which will decode session data and write logs for each sesssion. This script was called by incron
<?php
//log-session-data-change.php
$sessionLogStoragePath = '/var/www/html/logged-session-storage/';
$sessionFilePath = $argv[1];
$sessionOperationType = $argv[2];
$sessionFileName = basename($sessionFilePath);
session_start();
session_decode(file_get_contents($sessionFilePath));
$logString = sprintf(
'"%s","%s","%s",""' . PHP_EOL,
date(DateTime::COOKIE),
$sessionOperationType,
$sessionFileName
);
if (file_exists($sessionFilePath)) {
session_start();
session_decode(file_get_contents($sessionFilePath));
foreach ($_SESSION as $name => $data) {
$value = '<empty>';
if (isset($data['_session_validator_data']) && isset($data['_session_validator_data']['session_expire_timestamp'])) {
$value = $data['_session_validator_data']['session_expire_timestamp'];
}
$logString .= sprintf(
'"","","","%s","%s"' . PHP_EOL,
$name,
$value
);
}
}
file_put_contents($sessionLogStoragePath . $sessionFileName, $logString, FILE_APPEND);
and here is the corresponding incrontab
entry
/var/www/html/magento-doc-root/var/session IN_MODIFY,IN_CREATE,IN_DELETE,IN_MOVE /usr/bin/php /var/www/html/log-session-data-change.php $@/$# $%
sample output
"Wednesday, 05-Apr-2017 18:09:06 CEST","IN_MODIFY","sess_94rfglnua0phncmp98hbr3k524",""
"","","","core","1491408665"
"","","","customer_base","1491408665"
"","","","catalog","1491408665"
"","","","checkout","1491408665"
"","","","reports","1491408494"
"","","","store_default","1491408665"
"","","","rss","1491408524"
"","","","admin","1491408524"
Best Answer
Try to insert in your index file (outside of Magento):
It will give you an access to Magento core functionality like sessions etc. After that you will be able to set your custom variable
Then simply call anywhere in Magento: