cvs: pear /PECL/session_pgsql config.m4 session_pgsql.c session_pgsql.h
| From: | Yasuo Ohgaki | Date: | Wed, 23 Jan 2002 09:26:45 +0000 |
| Subject: | cvs: pear /PECL/session_pgsql config.m4 session_pgsql.c session_pgsql.h | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-2055@lists.php.net to get a copy of this message | ||
yohgaki Wed Jan 23 04:26:45 2002 EDT
Modified files:
/pear/PECL/session_pgsql config.m4 session_pgsql.c session_pgsql.h
Log:
Implement shared last_gc time. It does not gc multiple times now.
Add skelton for new function session_pgsql_info() - get std session info.
# Lock isn't used since race is not much problem here.
Index: pear/PECL/session_pgsql/config.m4
diff -u pear/PECL/session_pgsql/config.m4:1.2 pear/PECL/session_pgsql/config.m4:1.3
--- pear/PECL/session_pgsql/config.m4:1.2 Mon Jan 7 01:15:12 2002
+++ pear/PECL/session_pgsql/config.m4 Wed Jan 23 04:26:45 2002
@@ -1,6 +1,7 @@
dnl
-dnl $Id: config.m4,v 1.2 2002/01/07 06:15:12 yohgaki Exp $
+dnl $Id: config.m4,v 1.3 2002/01/23 09:26:45 yohgaki Exp $
dnl
+dnl FIXME: mm check
PHP_ARG_WITH(session-pgsql,for pgsql sesssion support,
[ --with-session-pgsql[=DIR] Include pgsql(PostgreSQL) support for session storage])
@@ -39,6 +40,7 @@
fi
PHP_ADD_LIBRARY_WITH_PATH(pq, $PGSQL_LIBDIR, SESSION_SHARED_LIBADD)
+ PHP_ADD_LIBRARY_WITH_PATH(mm, "/usr/lib", SESSION_SHARED_LIBADD)
PHP_ADD_INCLUDE($PGSQL_INCLUDE)
AC_DEFINE(HAVE_SESSION_PGSQL, 1, [Whether you have pgsql session save handler])
PHP_MODULE_PTR(phpext_ps_pgsql_ptr)
Index: pear/PECL/session_pgsql/session_pgsql.c
diff -u pear/PECL/session_pgsql/session_pgsql.c:1.13 pear/PECL/session_pgsql/session_pgsql.c:1.14
--- pear/PECL/session_pgsql/session_pgsql.c:1.13 Mon Jan 21 10:43:31 2002
+++ pear/PECL/session_pgsql/session_pgsql.c Wed Jan 23 04:26:45 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: session_pgsql.c,v 1.13 2002/01/21 15:43:31 yohgaki Exp $ */
+/* $Id: session_pgsql.c,v 1.14 2002/01/23 09:26:45 yohgaki Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -29,12 +29,24 @@
#include "ext/session/php_session.h"
#ifdef HAVE_SESSION_PGSQL
+#include "mm.h"
#include "session_pgsql.h"
ps_module ps_mod_pgsql = {
PS_MOD(pgsql)
};
+#define PS_PGSQL_FILE "/tmp/session_pgsql"
+
+typedef struct {
+ MM *mm;
+ time_t *last_gc;
+ pid_t owner;
+} ps_pgsql_instance_t;
+
+static ps_pgsql_instance_t *ps_pgsql_instance;
+
+
#ifdef ZTS
int ps_pgsql_globals_id;
#else
@@ -227,7 +239,9 @@
if (PS_PGSQL(pgsql_link)[id] == NULL || PQstatus(PS_PGSQL(pgsql_link)[id]) == CONNECTION_BAD) {
php_log_err("Sessin pgsql GC failed. Bad connection.");
}
- PQsendQuery(PS_PGSQL(pgsql_link)[id], query);
+ else {
+ PQsendQuery(PS_PGSQL(pgsql_link)[id], query);
+ }
}
return SUCCESS;
}
@@ -246,7 +260,21 @@
#endif
ELOG("MINIT Called");
- PS_PGSQL(last_gc) = time(NULL);
+ ps_pgsql_instance = calloc(sizeof(ps_pgsql_instance_t), 1);
+ if (!ps_pgsql_instance) {
+ return FAILURE;
+ }
+ ps_pgsql_instance->owner = getpid();
+ ps_pgsql_instance->mm = mm_create(0, PS_PGSQL_FILE);
+ if (!ps_pgsql_instance->mm) {
+ return FAILURE;
+ }
+ ps_pgsql_instance->last_gc = mm_calloc(ps_pgsql_instance->mm, 1, sizeof(time_t));
+ if (!ps_pgsql_instance->last_gc) {
+ mm_destroy(ps_pgsql_instance->mm);
+ return FAILURE;
+ }
+
php_session_register_module(&ps_mod_pgsql);
return SUCCESS;
}
@@ -263,6 +291,13 @@
for (i = 0; i < PS_PGSQL(servers); i++) {
PQfinish(PS_PGSQL(pgsql_link)[i]);
}
+ if (ps_pgsql_instance->owner == getpid() && ps_pgsql_instance->mm) {
+ if (ps_pgsql_instance->last_gc) {
+ mm_free(ps_pgsql_instance->mm, ps_pgsql_instance->last_gc);
+ }
+ mm_destroy(ps_pgsql_instance->mm);
+ free(ps_pgsql_instance);
+ }
return SUCCESS;
}
@@ -272,13 +307,15 @@
*/
PHP_RSHUTDOWN_FUNCTION(ps_pgsql)
{
- int ret = SUCCESS;
-
+ int ret;
+
ELOG("RSHUTDOWN Called");
- if (PS_PGSQL(last_gc) < time(NULL) - PS_PGSQL(gc_interval)) {
+ if (*(ps_pgsql_instance->last_gc) < time(NULL) - PS_PGSQL(gc_interval)) {
+ *(ps_pgsql_instance->last_gc) = time(NULL);
ret = php_ps_pgsql_gc();
}
- return ret;
+
+ return SUCCESS;
}
/* }}} */
@@ -441,6 +478,7 @@
PGconn *pg_link;
size_t query_len;
time_t now, exp;
+ char *data;
char *query;
char *query_delete =
"DELETE FROM php_session WHERE sess_id = '%s';";
@@ -468,22 +506,23 @@
now = time(NULL);
exp = now + PS(gc_maxlifetime);
- val = php_addslashes(val, strlen(val), &len, 0 TSRMLS_CC);
+ data = php_addslashes(val, strlen(val), &len, 0 TSRMLS_CC);
if (PS_PGSQL(sess_new)) {
/* INSERT */
- query_len = strlen(query_insert)+vallen+strlen(key)+120;
+ query_len = strlen(query_insert)+strlen(data)+strlen(key)+120;
query = emalloc(query_len+1);
- sprintf(query, query_insert, key, now, now, exp, val);
+ sprintf(query, query_insert, key, now, now, exp, data);
PQsendQuery(pg_link, query);
}
else {
/* UPDATE */
- query_len = strlen(query_update)+strlen(key)+vallen+120;
+ query_len = strlen(query_update)+strlen(key)+strlen(data)+120;
query = emalloc(query_len+1);
- sprintf(query, query_update, val, now, exp, key);
+ sprintf(query, query_update, data, now, exp, key);
PQsendQuery(pg_link, query);
}
efree(query);
+ efree(data);
/* PQsendQuery(pg_link, "END;"); */
PQexec(pg_link, "END;");
Index: pear/PECL/session_pgsql/session_pgsql.h
diff -u pear/PECL/session_pgsql/session_pgsql.h:1.7 pear/PECL/session_pgsql/session_pgsql.h:1.8
--- pear/PECL/session_pgsql/session_pgsql.h:1.7 Mon Jan 21 10:43:31 2002
+++ pear/PECL/session_pgsql/session_pgsql.h Wed Jan 23 04:26:45 2002
@@ -60,6 +60,7 @@
/* php function registration */
PHP_FUNCTION(session_pgsql_status);
+PHP_FUNCTION(session_pgsql_info);
PHP_FUNCTION(session_pgsql_add_error);
PHP_FUNCTION(session_pgsql_get_error);