From f6925611fb40499e9c357d7f6d95a7a4c1a96308 Mon Sep 17 00:00:00 2001 From: "Thies C. Arntzen" Date: Tue, 13 Feb 2001 18:28:24 +0000 Subject: [PATCH] @- PostgreSQL now does a rollback at the end of a request on every @ persistent connection. This is done by doing an "empty" transaction @ on the connection (This was advised by someone from the PostgreSQL @ core-team). If you leave transactions open on your page you will see a @ "NOTICE: BEGIN: already a transaction in progress" message in your @ apache error_log. This message is created by the PostgreSQL libs - we can @ do nothing about it. (Thies) --- ext/pgsql/pgsql.c | 35 ++++++++++++++++++++++++++++++++++- ext/pgsql/php_pgsql.h | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index ce4b7fc3b8..cbc09ba60f 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -93,7 +93,7 @@ zend_module_entry pgsql_module_entry = { PHP_MINIT(pgsql), PHP_MSHUTDOWN(pgsql), PHP_RINIT(pgsql), - NULL, + PHP_RSHUTDOWN(pgsql), PHP_MINFO(pgsql), STANDARD_MODULE_PROPERTIES }; @@ -145,6 +145,29 @@ static void _close_pgsql_plink(zend_rsrc_list_entry *rsrc) PGG(num_links)--; } +static int _rollback_transactions(zend_rsrc_list_entry *rsrc) +{ + PGconn *link = (PGconn *)rsrc->ptr; + /* + PGresult *pg_result; + ExecStatusType status; + */ + + PQexec(link,"BEGIN;ROLLBACK;"); + + /* maybe do error handling later.... + pg_result = PQexec(link,"BEGIN;ROLLBACK;"); + + if (pg_result) { + status = PQresultStatus(pg_result); + } else { + status = (ExecStatusType) PQstatus(link); + } + */ + + return 0; +} + static void _free_ptr(zend_rsrc_list_entry *rsrc) { @@ -213,6 +236,14 @@ PHP_RINIT_FUNCTION(pgsql) return SUCCESS; } +PHP_RSHUTDOWN_FUNCTION(pgsql) +{ + zend_hash_apply(&EG(persistent_list),_rollback_transactions); + + return SUCCESS; +} + + PHP_MINFO_FUNCTION(pgsql) { @@ -491,6 +522,8 @@ PHP_FUNCTION(pg_close) ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + printf("\npg_close %d\n",id); + if (id==-1) { /* explicit resource number */ zend_list_delete(Z_RESVAL_PP(pgsql_link)); } diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h index 37071c8395..e53670a1af 100644 --- a/ext/pgsql/php_pgsql.h +++ b/ext/pgsql/php_pgsql.h @@ -48,6 +48,7 @@ extern zend_module_entry pgsql_module_entry; PHP_MINIT_FUNCTION(pgsql); PHP_MSHUTDOWN_FUNCTION(pgsql); PHP_RINIT_FUNCTION(pgsql); +PHP_RSHUTDOWN_FUNCTION(pgsql); PHP_MINFO_FUNCTION(pgsql); PHP_FUNCTION(pg_connect); PHP_FUNCTION(pg_pconnect); -- 2.40.0