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

From: Date: Mon, 13 Jan 2003 13:19:12 +0000
Subject: cvs: pear /PECL/session_pgsql README package.xml session_pgsql.c session_pgsql.h
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8218@lists.php.net to get a copy of this message
yohgaki Mon Jan 13 08:19:12 2003 EDT Added files: /pear/PECL/session_pgsql package.xml Modified files: /pear/PECL/session_pgsql README session_pgsql.c session_pgsql.h Log: Added package.xml. Fixed typo and license. Updated README.

Index: pear/PECL/session_pgsql/README diff -u pear/PECL/session_pgsql/README:1.7 pear/PECL/session_pgsql/README:1.8 --- pear/PECL/session_pgsql/README:1.7 Wed Feb 20 04:18:02 2002 +++ pear/PECL/session_pgsql/README Mon Jan 13 08:19:11 2003 @@ -1,14 +1,114 @@ -PostgreSQL session save handler module README + PostgreSQL database session save handler module *WARNING* This session save handler is EXPERIMENTAL. Anything may be -changed/deleted/added without notice. +changed/deleted/added without notice. It is considered as pre-alpha. -mod_pgsql is a session save handler module. It provides session storage -with PostgreSQL database. This module is written by yohgaki@php.net. -Please report problems to http://bugs.php.net/ or php-dev@lists.php.net. +[What is it] -Session Table Definition +session_pgsql is an additional session save handler module. It +provides session storage using PostgreSQL database server(s). + + - C implantation of session save handler with PostgreSQL. It could + twice as fast or more compare to script version of save handler. + - Automatic session table creation. + - Better garbage collection. + - Multiple PostgreSQL servers support. + - Automatic db server failover(switching) when there is trouble. + - Automatic db server load balancing where there are multiple + PostgreSQL servers. + - Automatic session table vacuum. + +It is design to scale any size of web sites. + +[How to use] + +To compile PHP with mod_pgsql, you need "--with-session-pgsql[=DIR]" +when you configure PHP. [=DIR] is installation path for +PostgreSQL. You don't have to compile PHP with PostgreSQL module, but +your system must have libpq and headers installed. +It also uses libmm your system must have libmm and headers installed +to compile. + +Once you have successfully installed session_pgsql (and PHP of course) +and PostgreSQL to localhost. All you have to do is (as postgres super user) + +% createuser nobody +% createdb php_session + +In your php.ini +session.save_handler = pgsql +or +In your script (make sure you call it *first* and before staring session) +session_module_name('pgsql'); + +session_pgsql connects to local PostgreSQL backend and create session +table automatically if needed. If you would like to use remote PostgreSQL +server or even multiple PostgreSQL servers, edit session_pgsql.db php.ini +configuration directive. + +NOTE: It cannot be used with CGI/CLI binary. + +[php.ini settings] + +Following php.ini directives has special meanings for mod_pgsql + +session.save_handler + "pgsql" for session_pgsql session. + +session_pgsql.db + Valid PostgreSQL database connection string. + For example, "host=localhost dbname=php_session user=nobody" can + be set. This example is the default. + You can specify multiple PostgreSQL by separating ";". e.g. + "host=server1 dbname=php_session user=nobody;host=server2 dbname=php_session user=nobody" + If multiple servers are set, session_pgsql automatically balance + db server loads. If one of session db server fails, it will try to + use available db server automatically. + NOTE: database name must be "php_session". Other connection options + may be changed. + +session_pgsql.use_app_vars + Use application level variable ($_APP) or not. + Use different session name to change application. + i.e. use session_name('AppName') + Use of application variable has severe performance penalty. + Default is off + +session_pgsql.create_table + Automatically create session and application variable table + if set to on. session_pgsql creates tables, php_session and php_app_vers, + in the database. Default is on. + +session_pgsql.failover_mode + If failover_mode is set to on, it will always use 1st db server + and if 1st server fails, it will use next available db server. + create session and application variable table + if set to on. If this option is enabled, load balancing session + db server will not be enabled. Default is off. + NOTE: session_pgsql do not mirror session data. It just switch + to other database server to continue web services. + +session_pgsql.gc_interval + How often perform GC in seconds. Default is 3600 seconds. + If you set multiple db servers to session_pgsql.db, set only + one of your web server to prevent unneeded garbage collections. + It is good idea set to 0 (disable) and perform garbage collection + by using cron or like in db server if you have multiple web servers + accessed to the session db server(s). + +session_pgsql.vacuum_interval + How often perform GC in seconds. Default is 18000 seconds. + If you set multiple db servers to session_pgsql.db, set only + one of your web server to prevent unneeded vacuum operations. + It is good idea set to 0 (disable) and perform vacuum + by using cron or like in db server if you have multiple web servers + accessed to the session db server(s). + +[Known Problem] +Please report problem to the author. + +[Session Table Definition] CREATE TABLE php_session ( sess_id char(32), @@ -19,17 +119,17 @@ sess_expire integer, sess_addr_created cidr, sess_addr_modified cidr, + sess_counter integer, sess_error integer, sess_warning integer, sess_notice integer, sess_err_message text, - sess_counter integer, sess_reserved integer ); CREATE INDEX php_session_idx ON php_session USING BTREE (sess_id); -Application Variable Table Definition +[Application Variable Table Definition] CREATE TABLE php_app_vars ( app_modified integer, @@ -38,65 +138,22 @@ ); -NOTE: If you use HASH for index, you'll have deadlock problem. DO -NOT USE HASH INDEX. +NOTE: If you use HASH for index, you'll have deadlock problem when +server load *very* high. Even if it's unlikely to have deadlock under +normal operation, but it can. DO NOT USE HASH INDEX. User may *append* additional fields, sess_reserved fields are place holder for additional feature. Since mod_pgsql accesses field using field index, user must use this field order. -How to use - -To compile PHP with mod_pgsql, you need "--with-session-pgsql[=DIR]" -when you configure PHP. [=DIR] is installation path for -PostgreSQL. You don't have to compile PHP with PostgreSQL module, but -your system must have libpq and headers installed. - -Following php.ini directives has special meanings for mod_pgsql - -session.save_handler : "pgsql" for mod_pgsql session. -session.pgsql_db : Valid PostgreSQL database connection string. - For example, "host=pgsql dbname=session user=php" -session.pgsql_use_app_var : Use application level variable or not. - Use different session name to change application. - (i.e. use session_name('AppName')) -session.pgsql_create_table : Automatically create session and application - variable table. -session.pgsql_gc_interval : How often perform GC in seconds. Default - is 3600 seconds. - - -How it works - -It uses libpq which is written in C. It also uses aync query for -garbage collection. Therefore, user will not experience delay even if -garbage collection is performed. This module is much more efficient -than user handlers written in PHP. - -How fast pgsql session save handler is - -Here is summary of simple benchmark tests. This module is as fast as -files session save handler on my test system. I also compared with -equivalent user save handler with PostgreSQL database. This module is -2 times faster than PHP script version. msession handler is about 30% -faster than pgsql save handler. mm handler does not work for me :( - -How to customize - -Since mod_pgsql uses PostgreSQL database. User can add more fields to -session database and create session access functions as user -want. Keep in mind that user is not supposed to order of standard -fields. User fields are must be defined after mod_pgsql fields. - -Known Problem - - Many. - -ToDo +[ToDo] - More efficient application variable handling - - Simple fail over - - Load balancing -History - 0.1 is released 2002/1/12 +[History] + 0.4.0 + - Implemented most features that are planned. + 0.2 is released 2002/2/20 - Added application variable support. + + 0.1 is released 2002/1/12 Index: pear/PECL/session_pgsql/session_pgsql.c diff -u pear/PECL/session_pgsql/session_pgsql.c:1.26 pear/PECL/session_pgsql/session_pgsql.c:1.27 --- pear/PECL/session_pgsql/session_pgsql.c:1.26 Mon Jan 13 06:49:40 2003 +++ pear/PECL/session_pgsql/session_pgsql.c Mon Jan 13 08:19:11 2003 @@ -1,22 +1,12 @@ /* +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | + | This source file is subject to LGPL license. | +----------------------------------------------------------------------+ | Authors: Yasuo Ohgaki <yohgaki@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: session_pgsql.c,v 1.26 2003/01/13 11:49:40 yohgaki Exp $ */ +/* $Id: session_pgsql.c,v 1.27 2003/01/13 13:19:11 yohgaki Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -48,7 +38,7 @@ typedef struct { MM *mm; time_t *last_gc; - time_t *last_vaccum; + time_t *last_vacuum; pid_t owner; } ps_pgsql_instance_t; @@ -111,7 +101,7 @@ STD_PHP_INI_ENTRY("session.pgsql_use_app_vars","0", PHP_INI_SYSTEM, OnUpdateBool, use_app_vars, php_session_pgsql_globals, session_pgsql_globals) STD_PHP_INI_ENTRY("session.pgsql_serializable","0", PHP_INI_SYSTEM, OnUpdateBool, serializable, php_session_pgsql_globals, session_pgsql_globals) STD_PHP_INI_ENTRY("session.pgsql_gc_interval", "3600", PHP_INI_SYSTEM, OnUpdateInt, gc_interval, php_session_pgsql_globals, session_pgsql_globals) -STD_PHP_INI_ENTRY("session.pgsql_vaccum_interval", "18000", PHP_INI_SYSTEM, OnUpdateInt, vaccum_interval, php_session_pgsql_globals, session_pgsql_globals) +STD_PHP_INI_ENTRY("session.pgsql_vacuum_interval", "18000", PHP_INI_SYSTEM, OnUpdateInt, vacuum_interval, php_session_pgsql_globals, session_pgsql_globals) PHP_INI_END() /* }}} */ @@ -310,12 +300,13 @@ PGresult *pg_result; char query[QUERY_BUF_SIZE+1]; char *query_gc = "DELETE FROM php_session WHERE sess_expire < %d;"; - char *query_vaccum = "VACCUM php_session; VACCUM php_app_vars;"; + char *query_vacuum = "VACUUM php_session; VACUUM php_app_vars;"; int id; ELOG("GC Called"); sprintf(query, query_gc, time(NULL)); - if (*(ps_pgsql_instance->last_gc) < time(NULL) - PS_PGSQL(gc_interval)) { + if (*(ps_pgsql_instance->last_gc) && + *(ps_pgsql_instance->last_gc) < time(NULL) - PS_PGSQL(gc_interval)) { *(ps_pgsql_instance->last_gc) = time(NULL); for (id = 0; id < PS_PGSQL(servers); id++) { if (PS_PGSQL(pgsql_link)[id]) { @@ -324,11 +315,12 @@ } } } - if (*(ps_pgsql_instance->last_vaccum) < time(NULL) - PS_PGSQL(vaccum_interval)) { - *(ps_pgsql_instance->last_vaccum) = time(NULL); + if (*(ps_pgsql_instance->last_vacuum) && + *(ps_pgsql_instance->last_vacuum) < time(NULL) - PS_PGSQL(vacuum_interval)) { + *(ps_pgsql_instance->last_vacuum) = time(NULL); for (id = 0; id < PS_PGSQL(servers); id++) { if (PS_PGSQL(pgsql_link)[id]) { - pg_result = PQexec(PS_PGSQL(pgsql_link)[id], query_vaccum); + pg_result = PQexec(PS_PGSQL(pgsql_link)[id], query_vacuum); PQclear(pg_result); } } @@ -409,10 +401,10 @@ php_log_err("session pgsql: MM failure" TSRMLS_CC); return FAILURE; } - ps_pgsql_instance->last_vaccum = mm_calloc(ps_pgsql_instance->mm, 1, sizeof(time_t)); + ps_pgsql_instance->last_vacuum = mm_calloc(ps_pgsql_instance->mm, 1, sizeof(time_t)); ps_pgsql_instance->owner = getpid(); *(ps_pgsql_instance->last_gc) = time(NULL) + PS_PGSQL(gc_interval); - *(ps_pgsql_instance->last_vaccum) = time(NULL) + PS_PGSQL(vaccum_interval); + *(ps_pgsql_instance->last_vacuum) = time(NULL) + PS_PGSQL(vacuum_interval); /* init $_APP hash */ if (PS_PGSQL(use_app_vars)) { zend_register_auto_global("_APP", sizeof("_APP")-1 TSRMLS_CC); @@ -451,8 +443,8 @@ if (ps_pgsql_instance->last_gc) { mm_free(ps_pgsql_instance->mm, ps_pgsql_instance->last_gc); } - if (ps_pgsql_instance->last_vaccum) { - mm_free(ps_pgsql_instance->mm, ps_pgsql_instance->last_vaccum); + if (ps_pgsql_instance->last_vacuum) { + mm_free(ps_pgsql_instance->mm, ps_pgsql_instance->last_vacuum); } mm_destroy(ps_pgsql_instance->mm); free(ps_pgsql_instance); Index: pear/PECL/session_pgsql/session_pgsql.h diff -u pear/PECL/session_pgsql/session_pgsql.h:1.14 pear/PECL/session_pgsql/session_pgsql.h:1.15 --- pear/PECL/session_pgsql/session_pgsql.h:1.14 Mon Jan 13 05:34:03 2003 +++ pear/PECL/session_pgsql/session_pgsql.h Mon Jan 13 08:19:11 2003 @@ -1,16 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | + | This source file is subject to LGPL license. | +----------------------------------------------------------------------+ | Authors: yohgaki@php.net | +----------------------------------------------------------------------+ @@ -48,7 +38,7 @@ int use_app_vars; char *sem_file_name; int gc_interval; - int vaccum_interval; + int vacuum_interval; int failover_mode; int disable; Index: pear/PECL/session_pgsql/package.xml +++ pear/PECL/session_pgsql/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "../../../php4/pear/package.dtd"> <package> <name>session_pgsql</name> <summary>Session save handler using PostgreSQL database servers(s)</summary> <maintainers> <maintainer> <user>yohgaki</user> <name>Yasuo Ohgai</name> <email>yohgaki@php.net</email> <role>lead</role> </maintainer> </maintainers> <description> session_pgsql is an extension that provides additional session save handler for Session module. </description> <license>PHP</license> <release> <state>alpha</state> <version>0.4.0</version> <date>2002-01-10</date> <notes> - 1st Pre-alpha relase. </notes> <filelist> <file role="src" name="config.m4"/> <file role="src" name="session_pgsql.c"/> <file role="src" name="session_pgsql.h"/> <file role="doc" name="CREDITS"/> <file role="doc" name="README"/> <file role="test" name="tests/session_pgsql.phpt"/> </filelist> <deps> <dep type="ext" rel="has">session</dep> </deps> </release> </package>
« previous php.pear.cvs (#8218) next »