Permalink
Browse files

New feature: PHP session handler.

  • Loading branch information...
1 parent bfdc1ed commit 4963a9aa2b67c9891378e4fb1c8a99ee33963ac1 @nicolasff nicolasff committed Dec 2, 2010
Showing with 393 additions and 2 deletions.
  1. +11 −0 README.markdown
  2. +2 −2 config.m4
  3. +6 −0 redis.c
  4. +359 −0 redis_session.c
  5. +15 −0 redis_session.h
View
@@ -37,6 +37,17 @@ LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
</pre>
+Session handler (not production ready yet, preview only)
+==============
+
+phpredis can be used to store PHP sessions. To do this, configure `session.save_handler` and `session.save_path` in your php.ini to tell phpredis where to store the sessions:
+<pre>
+session.save_handler = redis
+session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2, tcp://host3:6379?weight=2"
+</pre>
+
+`session.save_path` can have a simple `host:port` format too, but you need to provide the `tcp://` scheme if you want to use the weight parameter.
+
Error handling
==============
View
@@ -46,5 +46,5 @@ if test "$PHP_REDIS" != "no"; then
dnl
dnl PHP_SUBST(REDIS_SHARED_LIBADD)
- PHP_NEW_EXTENSION(redis, redis.c library.c, $ext_shared)
-fi
+ PHP_NEW_EXTENSION(redis, redis.c library.c redis_session.c, $ext_shared)
+fi
View
@@ -28,13 +28,16 @@
#include "php_redis.h"
#include <zend_exceptions.h>
+#include "ext/session/php_session.h"
+
#include "library.h"
#define R_SUB_CALLBACK_CLASS_TYPE 1
#define R_SUB_CALLBACK_FT_TYPE 2
static int le_redis_sock;
+extern ps_module ps_mod_redis;
ZEND_DECLARE_MODULE_GLOBALS(redis)
@@ -294,6 +297,9 @@ PHP_MINIT_FUNCTION(redis)
zend_declare_class_constant_stringl(redis_ce, "AFTER", 5, "after", 5 TSRMLS_CC);
zend_declare_class_constant_stringl(redis_ce, "BEFORE", 6, "before", 6 TSRMLS_CC);
+ /* declare session handler */
+ php_session_register_module(&ps_mod_redis);
+
return SUCCESS;
}
Oops, something went wrong.

0 comments on commit 4963a9a

Please sign in to comment.