pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
question about postgres persistent connection in php
2+ messages / 2 participants
[nested] [flat]

* question about postgres persistent connection in php
@ 2005-03-29 03:43  Yulius Tjahjadi <yulius@xfire.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Yulius Tjahjadi @ 2005-03-29 03:43 UTC (permalink / raw)
  To: postgres-php@postgresql.org

Hi,

I have a question about the postgres interface in php.  The
implementation for
a persistent connection calls _rollback_transactions. I was just
wondering
what exactly does the bottom section do by calling BEGIN; and then
ROLLBACK;.
It would seem like it's wasting cpu cycles to start up a transaction and
then rolling back the transactions doing nothing.

I'm looking at php 4.3.10 and I'm using postgres 8.0.1.

yulius

/* {{{ _rollback_transactions
 */
static int _rollback_transactions(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
        PGconn *link;
        PGresult *res;
        int orig;

        if (Z_TYPE_P(rsrc) != le_plink)
                return 0;

        link = (PGconn *) rsrc->ptr;

        if (PQ_SETNONBLOCKING(link, 0)) {
                php_error_docref("ref.pgsql" TSRMLS_CC, E_NOTICE,
"Cannot set connection to blocking mode");
                return -1;
        }

        while ((res = PQgetResult(link))) {
                PQclear(res);
        }
        orig = PGG(ignore_notices);
        PGG(ignore_notices) = 1;
        res = PQexec(link,"BEGIN;");
        PQclear(res);
        res = PQexec(link,"ROLLBACK;");
        PQclear(res);
        PGG(ignore_notices) = orig;

        return 0;
}
/* }}} */



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: question about postgres persistent connection in php
@ 2005-03-29 07:05  Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 0 replies; 2+ messages in thread

From: Christopher Kings-Lynne @ 2005-03-29 07:05 UTC (permalink / raw)
  To: Yulius Tjahjadi <yulius@xfire.com>; +Cc: pgsql-php

> A majority of our sql statements in the logs are BEGIN; ROLLBACK; 
> that is created by the php persistent connection and I want to 
> see if I can get rid of them.

Try changing these lines:

         orig = PGG(ignore_notices);
         PGG(ignore_notices) = 1;
         res = PQexec(link,"BEGIN;");
         PQclear(res);
         res = PQexec(link,"ROLLBACK;");
         PQclear(res);
         PGG(ignore_notices) = orig;

to this:

         if ((PQprotocolVersion(link) >= 3 && PQtransactionStatus(link) 
!= PQTRANS_IDLE) || PQprotocolVersion(link) < 3)
         {
                 orig = PGG(ignore_notices);
                 PGG(ignore_notices) = 1;
                 res = PQexec(link,"ROLLBACK;");
                 PQclear(res);
                 PGG(ignore_notices) = orig;
         }

And recompile.

Chris



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-03-29 07:05 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-03-29 03:43 question about postgres persistent connection in php Yulius Tjahjadi <yulius@xfire.com>
2005-03-29 07:05 Re: question about postgres persistent connection in php Christopher Kings-Lynne <chriskl@familyhealth.com.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox