cvs: pear /PECL/session_pgsql README session_pgsql.c session_pgsql.h

From: Date: Sat, 12 Jan 2002 01:06:12 +0000
Subject: cvs: pear /PECL/session_pgsql README session_pgsql.c session_pgsql.h
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1910@lists.php.net to get a copy of this message
yohgaki Fri Jan 11 20:06:12 2002 EDT Modified files: /pear/PECL/session_pgsql README session_pgsql.c session_pgsql.h Log: Fix segfault (Do not return FAILURE for read/write functions) Fix deadlock problem (Do not use HASH INDEX for DB) Perform GC at RSHUTDOWN. README Update # Now it's stable and considered as beta :) Index: pear/PECL/session_pgsql/README diff -u pear/PECL/session_pgsql/README:1.3 pear/PECL/session_pgsql/README:1.4 --- pear/PECL/session_pgsql/README:1.3 Mon Jan 7 02:30:53 2002 +++ pear/PECL/session_pgsql/README Fri Jan 11 20:06:12 2002 @@ -1,7 +1,8 @@ PostgreSQL session save handler module README *WARNING* -This session save handler is EXPERIMENTAL. +This session save handler is EXPERIMENTAL. Anything may be +changed/deleted/added without notice. mod_pgsql is a session save handler module. It provides session strage with PostgreSQL database. This module is written by yohgaki@php.net. @@ -25,8 +26,10 @@ sess_reserved8 integer ); -CREATE INDEX php_session_idx ON php_session USING HASH (sess_id); +CREATE INDEX php_session_idx ON php_session USING BTREE (sess_id); +NOTE: If you use HASH for index, you'll have deadlock problem. DO +NOT USE HASH INDEX. User may *append* additional fields, sess_reserved* fields are place holder for additional feture. Since mod_pgsql accesses field using @@ -64,13 +67,9 @@ fields. User fields are must be defined after mod_pgsql fields. Known Problem - -There is deadlock problem with busy site. -Connection handling is not optimized as it should be. - + - Nothing. Please report if you find one. ToDo - - Simpile fail over - Load balancing - Automatic session table creation Index: pear/PECL/session_pgsql/session_pgsql.c diff -u pear/PECL/session_pgsql/session_pgsql.c:1.8 pear/PECL/session_pgsql/session_pgsql.c:1.9 --- pear/PECL/session_pgsql/session_pgsql.c:1.8 Mon Jan 7 04:16:09 2002 +++ pear/PECL/session_pgsql/session_pgsql.c Fri Jan 11 20:06:12 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: session_pgsql.c,v 1.8 2002/01/07 09:16:09 yohgaki Exp $ */ +/* $Id: session_pgsql.c,v 1.9 2002/01/12 01:06:12 yohgaki Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -74,7 +74,7 @@ static int php_ps_pgsql_connect(const char *conn_str) { - ELOG("php_pg_pgsql_connect() is called"); + ELOG("php_ps_pgsql_connect() is called"); if (PQstatus(PS_PGSQL(pgsql_link)) == CONNECTION_OK) { return SUCCESS; } @@ -94,6 +94,35 @@ return SUCCESS; } +static int php_ps_pgsql_gc(void) +{ + PGresult *pg_result; + char query[QUERY_BUF_SIZE+1]; + char *query_update = "DELETE FROM php_session WHERE sess_modified < %d;"; + int ret = FAILURE; + + ELOG("GC Called"); + if (PS_PGSQL(pgsql_link) == NULL || PQstatus(PS_PGSQL(pgsql_link)) == CONNECTION_BAD) { + php_error(E_NOTICE,"Sessin pgsql GC failed. Bad connection"); + return FAILURE; + } + + sprintf(query, query_update, time(NULL) - PS_PGSQL(maxlifetime)); + pg_result = PQexec(PS_PGSQL(pgsql_link), "BEGIN;"); + PQclear(pg_result); + pg_result = PQexec(PS_PGSQL(pgsql_link), query); + if (PQresultStatus(pg_result) == PGRES_TUPLES_OK) { +/* *nrdels = atoi(PQcmdTuples(pg_result)); */ + ret = SUCCESS; + } + PQclear(pg_result); + pg_result = PQexec(PS_PGSQL(pgsql_link), "END;"); + PQclear(pg_result); + + return ret; +} + + PHP_MINIT_FUNCTION(ps_pgsql) { #ifdef ZTS @@ -120,30 +149,21 @@ PHP_RINIT_FUNCTION(ps_pgsql) { ELOG("RINIT Called"); - if (PS(save_path) && PS(save_path)[0] == 'p' ) { - return php_ps_pgsql_connect(PS(save_path)); - } +/* if (PS(save_path) && PS(save_path)[0] == 'p' ) { */ +/* return php_ps_pgsql_connect(PS(save_path)); */ +/* } */ return SUCCESS; } PHP_RSHUTDOWN_FUNCTION(ps_pgsql) { -/* PGresult *pg_result = NULL; */ int ret = SUCCESS; ELOG("RSHUTDOWN Called"); - - /* clean up link just in case */ -/* if (PQstatus(PS_PGSQL(pgsql_link)) != CONNECTION_BAD) { */ -/* pg_result = PQexec(PS_PGSQL(pgsql_link), "BEGIN;ROLLBACK;"); */ -/* if (PQresultStatus(pg_result) != PGRES_COMMAND_OK) { */ -/* if (PQresultStatus(pg_result) != PGRES_NONFATAL_ERROR) { */ -/* php_error(E_NOTICE,"Session pgsql connection is BAD. (%s)", PQerrorMessage(PS_PGSQL(pgsql_link))); */ -/* ret = FAILURE; */ -/* } */ -/* } */ -/* PQclear(pg_result); */ -/* } */ + if (PS_PGSQL(gc)) { + PS_PGSQL(gc) = 0; + ret = php_ps_pgsql_gc(); + } return ret; } @@ -192,7 +212,8 @@ ret = FAILURE; } } - pg_result = PQexec(PS_PGSQL(pgsql_link), "BEGIN;"); + pg_result = PQexec(PS_PGSQL(pgsql_link), "BEGIN;SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;"); + pg_result = PQexec(PS_PGSQL(pgsql_link), "BEGIN"); if (PQresultStatus(pg_result) != PGRES_COMMAND_OK) { php_error(E_NOTICE,"Session pgsql OPEN failed. Transaction cannot be started."); ret = FAILURE; @@ -271,7 +292,6 @@ else { php_error(E_WARNING,"Session pgsql READ failed: %s (%s)", PQerrorMessage(PS_PGSQL(pgsql_link)), query); - ret = FAILURE; } PQclear(pg_result); } @@ -279,7 +299,8 @@ *val = safe_estrndup("",0); } - return ret; +/* return ret; */ + return SUCCESS; } PS_WRITE_FUNC(pgsql) @@ -303,7 +324,6 @@ return FAILURE; } if (PS_PGSQL(sess_del)) { - /* DELETE */ query_len = strlen(query_delete)+strlen(key); query = emalloc(query_len+1); sprintf(query, query_delete, key); @@ -331,13 +351,13 @@ } else { php_error(E_WARNING,"Session pgsql WRITE failed: %s (%s)", - PQerrorMessage(PS_PGSQL(pgsql_link)), PQresultErrorMessage(pg_result)); - ret = FAILURE; + PQerrorMessage(PS_PGSQL(pgsql_link)), query); } PQclear(pg_result); efree(query); - return ret; +/* return ret; */ + return SUCCESS; } PS_DESTROY_FUNC(pgsql) @@ -371,26 +391,10 @@ PS_GC_FUNC(pgsql) { - PGresult *pg_result; - char query[QUERY_BUF_SIZE+1]; - char *query_update = "DELETE FROM php_session WHERE sess_modified < %d"; - int ret = FAILURE; - - ELOG("GC Called"); - if (PS_PGSQL(pgsql_link) == NULL || PQstatus(PS_PGSQL(pgsql_link)) == CONNECTION_BAD) { - php_error(E_NOTICE,"Sessin pgsql GC failed. Bad connection"); - return FAILURE; - } - - sprintf(query, query_update, time(NULL) - maxlifetime); - pg_result = PQexec(PS_PGSQL(pgsql_link), query); - if (PQresultStatus(pg_result) == PGRES_TUPLES_OK) { - *nrdels = atoi(PQcmdTuples(pg_result)); - ret = SUCCESS; - } - PQclear(pg_result); - - return ret; + PS_PGSQL(maxlifetime) = maxlifetime; + PS_PGSQL(gc) = 1; + *nrdels = 0; + return SUCCESS; } #endif Index: pear/PECL/session_pgsql/session_pgsql.h diff -u pear/PECL/session_pgsql/session_pgsql.h:1.3 pear/PECL/session_pgsql/session_pgsql.h:1.4 --- pear/PECL/session_pgsql/session_pgsql.h:1.3 Mon Jan 7 01:15:12 2002 +++ pear/PECL/session_pgsql/session_pgsql.h Fri Jan 11 20:06:12 2002 @@ -40,6 +40,8 @@ PGconn *pgsql_link; int sess_new; int sess_del; + int gc; + int maxlifetime; } php_ps_pgsql_globals; #ifdef ZTS

« previous php.pear.cvs (#1910) next »