stanley-king 3 tahun lalu
induk
melakukan
ad74e4f0c5
2 mengubah file dengan 66 tambahan dan 58 penghapusan
  1. 35 24
      core/framework/cache/cache.redis.php
  2. 31 34
      helper/fcgisrv/MobileServer.php

+ 35 - 24
core/framework/cache/cache.redis.php

@@ -8,7 +8,6 @@ defined('InShopNC') or exit('Access Invalid!');
 class CacheRedis extends Cache
 {
 	private $config;
-	private $connected;
 	private $type;
 	private $prefix;
     public function __construct()
@@ -24,34 +23,45 @@ class CacheRedis extends Cache
     private function init_master()
     {
     	static $_cache;
-    	if (isset($_cache)){
-    		$this->handler = $_cache;
-    	}else{
-	        $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
-	        $this->handler  = new Redis;
-	        $this->enable = $this->handler->$func($this->config['master']['host'], $this->config['master']['port']);
-	        $_cache = $this->handler;
+    	if (isset($_cache))
+    	{
+    	    if($_cache->isConnected()) {
+                $this->handler = $_cache;
+                return;
+            } else {
+                $_cache->close();
+                Log::record("CacheRedis init_slave disconnect.",Log::DEBUG);
+            }
     	}
-    }
 
-    private function init_slave(){
-    	static $_cache;
-    	if (isset($_cache)){
-    		$this->handler = $_cache;
-    	}else{
-	        $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
-	        $this->handler = new Redis;
-	        $this->enable = $this->handler->$func($this->config['slave']['host'], $this->config['slave']['port']);
-	        $_cache = $this->handler;
-    	}
+        $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
+        $this->handler  = new Redis();
+        $this->enable = $this->handler->$func($this->config['master']['host'], $this->config['master']['port']);
+        $_cache = $this->handler;
     }
 
-    private function isConnected() {
-    	$this->init_master();
-        return $this->enable;
+    private function init_slave()
+    {
+        static $_cache;
+        if (isset($_cache))
+        {
+            if($_cache->isConnected()) {
+                $this->handler = $_cache;
+                return;
+            } else {
+                $_cache->close();
+                Log::record("CacheRedis init_slave disconnect.",Log::DEBUG);
+            }
+        }
+
+        $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
+        $this->handler = new Redis();
+        $this->enable = $this->handler->$func($this->config['slave']['host'], $this->config['slave']['port']);
+        $_cache = $this->handler;
     }
 
-	public function get($key, $prefix = ''){
+	public function get($key, $prefix = '')
+    {
 		$this->init_slave();
 		if (!$this->enable) return false;
 		$this->type = $prefix;
@@ -60,7 +70,8 @@ class CacheRedis extends Cache
         return unserialize($value);
 	}
 
-    public function set($key, $value, $prefix = '', $expire = null) {
+    public function set($key, $value, $prefix = '', $expire = null)
+    {
     	$this->init_master();
     	if (!$this->enable) return false;
     	$this->type = $prefix;

+ 31 - 34
helper/fcgisrv/MobileServer.php

@@ -97,45 +97,42 @@ class MobileServer extends BaseServer
                     Log::record("Call {$file}",Log::DEBUG);
                     include $file;
                 }
-                else
+                elseif(defined('COMPANY_NAME') && COMPANY_NAME === 'XYZ_COMPANY')
                 {
                     //部分控制器不需要使用session.
-                    if(defined('COMPANY_NAME') && COMPANY_NAME === 'XYZ_COMPANY')
-                    {
-                        $act = $_GET['act'];
-                        if ($act == 'refill') {
-                            Base::mobile_control();
-                        } else {
-                            fcgi_header("Content-Type: text/html; charset=UTF-8");
-                            echo "no such file.";
-                        }
-                        session::instance()->end(false);
+                    $act = $_GET['act'];
+                    if ($act == 'refill') {
+                        Base::mobile_control();
+                    } else {
+                        fcgi_header("Content-Type: text/html; charset=UTF-8");
+                        echo "no such file.";
+                    }
+                    session::instance()->end(false);
+                }
+                else
+                {
+                    if(!isset($_GET['act'])) {
+                        $_GET['act'] = 'index';
+                    }
+                    if(!isset($_GET['op'])) {
+                        $_GET['op'] = 'index';
+                    }
+                    if(!isset($_POST['act'])) {
+                        $_POST['act'] = 'index';
+                    }
+                    if(!isset($_POST['op'])) {
+                        $_POST['op'] = 'index';
                     }
-                    else
-                    {
-                        if(!isset($_GET['act'])) {
-                            $_GET['act'] = 'index';
-                        }
-                        if(!isset($_GET['op'])) {
-                            $_GET['op'] = 'index';
-                        }
-                        if(!isset($_POST['act'])) {
-                            $_POST['act'] = 'index';
-                        }
-                        if(!isset($_POST['op'])) {
-                            $_POST['op'] = 'index';
-                        }
-
-                        //部分控制器不需要使用session.
-                        $act = $_GET['act'];
-                        if($act != 'refill') {
-                            session::instance()->start();
-                            Log::record("member_id=" . session_helper::memberid(),Log::DEBUG);
-                        }
 
-                        Base::mobile_control();
-                        session::instance()->end(true);
+                    //部分控制器不需要使用session.
+                    $act = $_GET['act'];
+                    if($act != 'refill') {
+                        session::instance()->start();
+                        Log::record("member_id=" . session_helper::memberid(),Log::DEBUG);
                     }
+
+                    Base::mobile_control();
+                    session::instance()->end(true);
                 }
             }
             else