First, if you’re using PHP-FPM (or other threaded models) and the phpredis library, persistent connections are not possible.
If you’d like to use persistent connections, just use any string (magestore1
) as the value for the persistent node in local.xml. As I understand it, this string has to be unique to your particular Magento installation, as multiple Magento virtual hosts on a single server would experience collisions if they shared <persistent />
values.
The pros:
- Faster response times across all pages; the delay in connecting to Redis is about
0.001
seconds, in my experience with phpredis.
- Fewer system calls for opening and closing sockets, so there’s slightly less CPU overhead.
The cons:
- Currently impossible with PHP-FPM and phpredis
- Odd issues are possibly more difficult to debug
- Bugs and segfaults can leave sockets open, requiring a system reboot to resolve odd connectivity failures
If the wrong session is used, it is because the session_name is wrong. The session name is set in Mage_Core_Model_Session_Abstract_Varien::setSessionName()
.
But after a look on the Stacktrace, I have no idea, why overwriting _construct
or even __construct
should be a problem here:
#0 Mage_Core_Model_Session_Abstract_Varien->setSessionName(frontend) called at [app/code/core/Mage/Core/Model/Session/Abstract/Varien.php:111]
#1 Mage_Core_Model_Session_Abstract_Varien->start(frontend) called at [app/code/core/Mage/Core/Model/Session/Abstract/Varien.php:166]
#2 Mage_Core_Model_Session_Abstract_Varien->init(core, frontend) called at [app/code/core/Mage/Core/Model/Session/Abstract.php:84]
#3 Mage_Core_Model_Session_Abstract->init(core, frontend) called at [app/code/core/Mage/Core/Model/Session.php:42]
#4 Mage_Core_Model_Session->__construct(Array ([name] => frontend)) called at [app/code/core/Mage/Core/Model/Config.php:1348]
#5 Mage_Core_Model_Config->getModelInstance(core/session, Array ([name] => frontend)) called at [app/Mage.php:462]
#6 Mage::getModel(core/session, Array ([name] => frontend)) called at [app/Mage.php:476]
#7 Mage::getSingleton(core/session, Array ([name] => frontend)) called at [app/code/core/Mage/Core/Controller/Varien/Action.php:494]
#8 Mage_Core_Controller_Varien_Action->preDispatch() called at [app/code/core/Mage/Core/Controller/Front/Action.php:64]
#9 Mage_Core_Controller_Front_Action->preDispatch() called at [app/code/core/Mage/Core/Controller/Varien/Action.php:408]
#10 Mage_Core_Controller_Varien_Action->dispatch(view) called at [app/code/core/Mage/Core/Controller/Varien/Router/Standard.php:250]
#11 Mage_Core_Controller_Varien_Router_Standard->match(Mage_Core_Controller_Request_Http Object ([] => /test.html,[] => ,[] => /test.html,[] => ,[] => ,[] => Array (),[] => catalog,[] => ,[] => Mage_Catalog,[] => ,[] => Array (),[] => Array ([0] => _GET,[1] => _POST),[] => /catalog/product/view/id/21,[] => ,[] => ,[] => catalog/product/view/id/21,[] => Array ([id] => 21),[] => ,[] => Array ([rewrite_request_path] => test.html),[] => 1,[] => catalog,[] => module,[] => product,[] => controller,[] => view,[] => action)) called at [app/code/core/Mage/Core/Controller/Varien/Front.php:176]
#12 Mage_Core_Controller_Varien_Front->dispatch() called at [app/code/core/Mage/Core/Model/App.php:354]
#13 Mage_Core_Model_App->run(Array ([scope_code] => ,[scope_type] => store,[options] => Array ())) called at [app/Mage.php:683]
#14 Mage::run(, store) called at [index.php:87]
Best Answer
BOT & SESSION
I'm not sure Bot needs sessions and the answer may be different for every bot for sure they don't store a cookie so it is no possible to re-use the old session matching the session ID stored in the client cookie.
How other E-Commerce fix this
Prestashop folks revolved the problem in this way:
Unfortunately, Magento doesn't store the IP along with the session ID, I guess this is because Magento support more backend for session (files, DB, Redis)
How I fixed it
There is another question actually there is a similar question Magento generating aprox 20 session files per minute
I used the information in the old question to create a solution that integrates the Prestashop approach while it is still compatible with all Magento session backend
All the Magento session magic happens here:
app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
This is an
abstract
that is extended by all the other session models, so you cannot simplyrewrite
it but only copy it in /local/Mage/Core/Model/Session/Abstract/Varien.php
.So the below code do 3 things:
In short
Add the following methods to your copy of
Mage_Core_Model_Session_Abstract_Varien
and change the
getSessionId()
in this wayYou may also want to change the behavior in case the bot access via HTTPS inside
start()
when you seesession_regenerate_id(false);
Note
The bot session Id will be a little longer, sha1 function:
this should not be a problem since PHP allows session to be 128 character long