I am trying to find out solution for issue "Mage registry key "_singleton/customer/session" already exists".
I am trying to many thing but still not success.
I am write my error report here if any one know solution and how can i debug my issue please post your answer.
Magento – Magento 1.9.3 magento Mage registry key “_singleton/customer/session” already exists
magento1.9.3
Related Solutions
Try next:
Go to downloader/Maged/Connect.php, find
var response = transport.responseJSON || transport.responseText.JSONeval(true) || {};
replace it with:
var response = transport.responseJSON || JSON.parse(transport.responseText) || {};
This works for me when i try to install extension with "Exception during cache and session cleaning" message. Hope, this solution will help you.
After some advanced debugging, session tracing and thinking about all that magic I was able to reproduce the problem and understand the reason for it. I prepared a little timing illustration, you can see it below.
- red flag is the moment of user login and session creation
- blue flag is the moment when user opens catalog page, let's assume it is a category page which is opened.
- green flag is the moment where user submits the order (
/sales/order/save/...
request)
Here is how to reproduce:
- Before you start: Set your PHP session timeout and Magento cookie timeout both to be 1440 which is a default PHP value.
- Kill all your cookies or open the incognito tab.
- Go to your Magento shop and login (see Flag 1)
- Go through catalog and add some products to the cart (Flag 2)
- Go through the checkout and submit an order. Note the time when you did it. (Flag 3)
- Go through catalog and add some products to the cart (Flag 4)
- Keep refreshing your cart page or going through catalog pages so long that the timeout which you have configured for magento cookies expires (Flags 5-6). Note that time between Flag 7 and Flag 3 should be bigger than the cookie timeout.
- Go through the checkout and submit an order (Flag 7). The order submission will fail due to the exception described in my question above.
Reason:
There are certain sessions which are only instantiated on given requests, e.g.
Mage_Rss_Model_Session
is only instantiated during the actual checkout and not while browsing through catalog. At the same time session expiry timestamp is only set when session was instantiated. That means that if there was enough time between two checkouts and the session was not killed meanwhile (because user logged out or cookie expired) the new Magento code will consider that session as not passing validation and will throw an exception, which sounds somehow strange to me.
How to fix:
Well, I have few options:
- Wait till Magento reacts on that and reconsiders that code.
- Remove this code meanwhile.
- Try setting Magento cookie timeout to 0 if that is an option for you.
How did I figure it out:
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.
Then I started thinking on how can I trace all changes to session data and came across this question https://superuser.com/questions/368231/automatic-versioning-upon-file-change-modify-create-delete I decided to give a try to
git
andincron
combination, but after I implemented it and tested in sandbox, I realized that I will run out of disk space really fast in production.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"
P.S.:
Current versions of both
skin/frontend/enterprise/default/js/opcheckout.js
src/skin/frontend/base/default/js/opcheckout.js
are not able to handle the exception above during the AJAX request. They display literally nothing to the user, while user effectively gets logged out!
P.P.S.:
apparently Magento CE 1.9.3.x versions are also affected, see https://github.com/OpenMage/magento-mirror/blame/magento-1.9/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
P.P.P.S.:
When I said "Remove this code meanwhile." I meant excluding the following block
if ($this->useValidateSessionExpire()
&& isset($sessionData[self::VALIDATOR_SESSION_EXPIRE_TIMESTAMP])
&& $sessionData[self::VALIDATOR_SESSION_EXPIRE_TIMESTAMP] < time() ) {
return false;
} else {
$this->_data[self::VALIDATOR_KEY][self::VALIDATOR_SESSION_EXPIRE_TIMESTAMP]
= $validatorData[self::VALIDATOR_SESSION_EXPIRE_TIMESTAMP];
}
you can do that with so many ways, including:
- Simply deleting that bit from the file
- Commenting it out
- Returning before it
- Making
$this->useValidateSessionExpire()
return true - ...
- It is programming - be creative ;)
Best Answer
This is happened because you have already registered the same key name _singleton/customer/session.
File: app/Mage.php/
you can see below function in this fileWe can see that any object or value we’re storing in the registry is ultimately being stored in the static $_registry class variable. We can also see that before storing the value, Magento checks if it’s already set. If so, Magento will either throw an Exception (the default behavior) or gracefully return null
its already set with other value
Finally, if you want to make you variable unavailable, you can use the unregister method to remove it from the registry.
Try this too
this will disable the compilation and will clear the files, after this delete content of var/cache/* and var/session/* by this command: