From ab6070fca5de90d1b645ae95a54e18a0c82f4be0 Mon Sep 17 00:00:00 2001
From: Thomas Steur <thomas.steur@googlemail.com>
Date: Thu, 6 Feb 2014 22:24:07 +0100
Subject: [PATCH] refs #4439 disable eAccelerator if enabled (just disabling
 optimizing did not work) and display a message in the admin UI. Also disabled
 eAccelerator during tracking. We might need to move the method to detect
 eAccelerator to another place, not sure if this is the best one

---
 core/Plugin/ControllerAdmin.php | 34 +++++++++++++++++++++++++++++++++
 core/dispatch.php               |  3 +++
 lang/en.json                    |  3 ++-
 piwik.php                       |  6 ++++++
 4 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/core/Plugin/ControllerAdmin.php b/core/Plugin/ControllerAdmin.php
index 41c14ff67b..72ef900287 100644
--- a/core/Plugin/ControllerAdmin.php
+++ b/core/Plugin/ControllerAdmin.php
@@ -27,6 +27,8 @@ use Piwik\View;
  */
 abstract class ControllerAdmin extends Controller
 {
+    private static $isEacceleratorUsed = false;
+
     private static function notifyWhenTrackingStatisticsDisabled()
     {
         $statsEnabled = PiwikConfig::getInstance()->Tracker['record_statistics'];
@@ -97,6 +99,37 @@ abstract class ControllerAdmin extends Controller
         }
     }
 
+    /**
+     * See http://dev.piwik.org/trac/ticket/4439#comment:8 and https://github.com/eaccelerator/eaccelerator/issues/12
+     *
+     * Eaccelerator does not support closures and is known to be not comptabile with Piwik. Therefore we are disabling
+     * it automatically. At this point it looks like Eaccelerator is no longer under development and the bug has not
+     * been fixed within a year.
+     */
+    public static function disableEacceleratorIfEnabled()
+    {
+        $isEacceleratorUsed = ini_get('eaccelerator.enable');
+
+        if (!empty($isEacceleratorUsed)) {
+            self::$isEacceleratorUsed = true;
+
+            @ini_set('eaccelerator.enable', 0);
+        }
+    }
+
+    private static function notifyIfEAcceleratorIsUsed()
+    {
+        if (self::$isEacceleratorUsed) {
+            $params  = array('<a href="http://dev.piwik.org/trac/ticket/4439">', '</a>');
+            $message = Piwik::translate('CoreAdminHome_EacceleratorNotCompatible', $params);
+
+            $notification = new Notification($message);
+            $notification->context = Notification::CONTEXT_WARNING;
+            $notification->raw     = true;
+            Notification\Manager::notify('ControllerAdmin_EacceleratorIsUsed', $notification);
+        }
+    }
+
     /**
      * Assigns view properties that would be useful to views that render admin pages.
      *
@@ -123,6 +156,7 @@ abstract class ControllerAdmin extends Controller
     static public function setBasicVariablesAdminView(View $view)
     {
         self::notifyWhenTrackingStatisticsDisabled();
+        self::notifyIfEAcceleratorIsUsed();
 
         $view->topMenu = MenuTop::getInstance()->getMenu();
         $view->currentAdminMenuName = MenuAdmin::getInstance()->getCurrentAdminMenuName();
diff --git a/core/dispatch.php b/core/dispatch.php
index 42e5a950f7..a0a4e312db 100644
--- a/core/dispatch.php
+++ b/core/dispatch.php
@@ -11,6 +11,9 @@
 use Piwik\Error;
 use Piwik\ExceptionHandler;
 use Piwik\FrontController;
+use \Piwik\Plugin\ControllerAdmin as PluginControllerAdmin;
+
+PluginControllerAdmin::disableEacceleratorIfEnabled();
 
 if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) {
     require_once PIWIK_INCLUDE_PATH . '/core/Error.php';
diff --git a/lang/en.json b/lang/en.json
index 1dbcea0f44..da10eeefa0 100644
--- a/lang/en.json
+++ b/lang/en.json
@@ -585,7 +585,8 @@
         "PluginSettingsIntro": "Here you can change the settings for the following 3rd party plugins:",
         "PluginSettingsValueNotAllowed": "The value for field \"%s\" in plugin \"%s\" is not allowed",
         "PluginSettingChangeNotAllowed": "You are not allowed to change the value of the setting \"%s\" in plugin \"%s\"",
-        "PluginSettings": "Plugin settings"
+        "PluginSettings": "Plugin settings",
+        "EacceleratorNotCompatible": "You are using the PHP accelerator & optimizer eAccelerator which is known to be not compatible with Piwik. We have disabled eAccelerator therefore which might affect the performance of Piwik. Read the %srelated ticket%s for more information and how to fix this problem."
     },
     "CoreHome": {
         "InjectedHostWarningIntro": "You are now accessing Piwik from %1$s, but Piwik has been configured to run at this address: %2$s.",
diff --git a/piwik.php b/piwik.php
index 8f9a68d637..263b3b0de7 100644
--- a/piwik.php
+++ b/piwik.php
@@ -35,6 +35,11 @@ if (!defined('PIWIK_INCLUDE_PATH')) {
 
 @ignore_user_abort(true);
 
+require_once PIWIK_INCLUDE_PATH . '/core/Plugin/Controller.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Plugin/ControllerAdmin.php';
+
+\Piwik\Plugin\ControllerAdmin::disableEacceleratorIfEnabled();
+
 require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
 require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php';
 require_once PIWIK_INCLUDE_PATH . '/core/Singleton.php';
@@ -78,6 +83,7 @@ session_cache_limiter('nocache');
 if (!defined('PIWIK_ENABLE_TRACKING') || PIWIK_ENABLE_TRACKING) {
     ob_start();
 }
+
 if ($GLOBALS['PIWIK_TRACKER_DEBUG'] === true) {
     require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
 
-- 
GitLab