Browse Source

add to local

stanley-king 9 years ago
parent
commit
6eba6786ee
2 changed files with 10 additions and 5 deletions
  1. 1 0
      fcgi_run.php
  2. 9 5
      helper/session.php

+ 1 - 0
fcgi_run.php

@@ -58,6 +58,7 @@ function run_fcgi()
                 fcgi_header("Content-Type: text/html; charset=UTF-8");
                 echo "no such file.";
             }
+            $_SESSION['name'] = 'stanley';
 
             session::instance()->end();
         }

+ 9 - 5
helper/session.php

@@ -36,8 +36,8 @@ class session
 
     public function init()
     {
-        @ini_set("session.save_handler", "redis");
-        session_save_path(self::save_path);
+//        @ini_set("session.save_handler", "redis");
+//        session_save_path(self::save_path);
         session_set_save_handler(
             array(&$this,'onOpen'),
             array(&$this,'onClose'),
@@ -81,12 +81,15 @@ class session
         $ret = $this->redis->hGet(self::prefix,$sid);
         if(empty($ret))
         {
+            Log::record("onRead " . $_COOKIE[self::session_name],Log::DEBUG);
+
             if(empty($_COOKIE[self::session_name]) || $_COOKIE[self::session_name] != $sid) {
                 Log::record("onRead fcgi_setcookie reset cookie",Log::DEBUG);
                 fcgi_setcookie("PHPSESSID","{$sid}",time() + self::sid_expire);
             }
             return '';
         } else {
+            Log::record("onRead 2",Log::DEBUG);
             return $ret[0];
         }
     }
@@ -98,11 +101,12 @@ class session
 
     public function onWrite($sid, $data) {
         Log::record("onWrite sid={$sid}",Log::DEBUG);
+
         $ret = $this->redis->hSet(self::prefix,$sid,$data);
-        if($ret != false) {
-            $this->redis->expire();
+        if($ret) {
+            $ret = $this->redis->expire(self::prefix . ":" . $sid, self::sid_expire);
         }
-
+        return true;
     }
 
     public function onDestroy($sid) {