colinmollenhour / Cm_RedisSession

Redis-based session handler for Magento with optimistic locking
208 stars 121 forks source link

Fatal Error when compilation is enabled #171

Closed dandrikop closed 1 year ago

dandrikop commented 5 years ago

I have installed the Cm_RedisSession on Magento 1.7.0.2 and runs fine. However, if I enable the compiler I get the below error page:

Fatal error: Class 'Cm\RedisSession\Handler' not found in /includes/src/Cm_RedisSession_Model_Session.php on line 60

When I disable the compiler everything works fine.

fredden commented 1 year ago

I was able to fix this locally by making the following changes to the 2.4.0 tag. There doesn't appear to be a branch for the 2.x release line, so I can't open a pull request with this specific change. @colinmollenhour please can you create such a branch, or is the 2.x release line now unsupported?

diff --git a/app/code/local/Cm/RedisSession/Model/Session.php b/app/code/local/Cm/RedisSession/Model/Session.php
index 5c14563..e5428b2 100644
--- a/app/code/local/Cm/RedisSession/Model/Session.php
+++ b/app/code/local/Cm/RedisSession/Model/Session.php
@@ -39,6 +39,16 @@ if (is_dir(__DIR__.'/../lib/src/Cm/RedisSession')) {
     require_once __DIR__.'/../lib/src/Cm/RedisSession/ConcurrentConnectionsExceededException.php';
 }

+foreach (['/Cm_RedisSession_lib_src_Cm_RedisSession_ConcurrentConnectionsExceededException.php',
+             '/Cm_RedisSession_lib_src_Cm_RedisSession_ConnectionFailedException.php',
+             '/Cm_RedisSession_lib_src_Cm_RedisSession_Handler_ConfigInterface.php',
+             '/Cm_RedisSession_lib_src_Cm_RedisSession_Handler_LoggerInterface.php',
+             '/Cm_RedisSession_lib_src_Cm_RedisSession_Handler.php'] as $file) {
+    if (file_exists(__DIR__ . $file)) {
+        require_once __DIR__ . $file;
+    }
+}
+
 class Cm_RedisSession_Model_Session implements \Zend_Session_SaveHandler_Interface
 {

diff --git a/app/code/local/Cm/RedisSession/Model/Session/Handler.php b/app/code/local/Cm/RedisSession/Model/Session/Handler.php
index 08a5015..fa0f31e 100644
--- a/app/code/local/Cm/RedisSession/Model/Session/Handler.php
+++ b/app/code/local/Cm/RedisSession/Model/Session/Handler.php
@@ -39,6 +39,16 @@ if (is_dir(__DIR__.'/../../lib/src/Cm/RedisSession')) {
     require_once __DIR__.'/../../lib/src/Cm/RedisSession/ConcurrentConnectionsExceededException.php';
 }

+foreach (['/Cm_RedisSession_lib_src_Cm_RedisSession_ConcurrentConnectionsExceededException.php',
+             '/Cm_RedisSession_lib_src_Cm_RedisSession_ConnectionFailedException.php',
+             '/Cm_RedisSession_lib_src_Cm_RedisSession_Handler_ConfigInterface.php',
+             '/Cm_RedisSession_lib_src_Cm_RedisSession_Handler_LoggerInterface.php',
+             '/Cm_RedisSession_lib_src_Cm_RedisSession_Handler.php'] as $file) {
+    if (file_exists(__DIR__ . $file)) {
+        require_once __DIR__ . $file;
+    }
+}
+
 class Cm_RedisSession_Model_Session_Handler extends \Cm\RedisSession\Handler
 {
     public function __construct()
colinmollenhour commented 1 year ago

@fredden I created a branch no-composer based on 2.4.0 if you want to submit a PR. It could be optimized for non-compiler users by adding else { break; }.

Does using compiler benefit performance significantly at this point?

fredden commented 1 year ago

Thanks very much for this @colinmollenhour. I've opened a pull request including your suggestion for optimisation.

Does using compiler benefit performance significantly at this point?

I don't know. After making the change above locally, I encountered other modules which were similarly incompatible, so I couldn't test the impact properly without spending time fixing those too. The project I was working on was time-limited and has finished now. I'm unlikely to be able to revisit this feature in the short term.

Thanks too for making such a wonderful contribution to the platform over the years! This code runs on a very large number of websites these days.

colinmollenhour commented 1 year ago

You're quite welcome! Thanks for the PR! It is merged and tagged as 2.5.0.