pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
2 distinct connections
4+ messages / 3 participants
[nested] [flat]

* 2 distinct connections
@ 2006-05-27 12:37  Martin Marques <martin@bugs.unl.edu.ar>
  0 siblings, 2 replies; 4+ messages in thread

From: Martin Marques @ 2006-05-27 12:37 UTC (permalink / raw)
  To: pgsql-php

We're working on a project using PHP and PostgreSQL, mainly trying to work 
in an OOP fashion. The project has quite a good amount of code, and a DB 
Object called DB_Bib that has all the query methods. I also have a generic 
DB object (DB_Main) which has code to establesh the connection, and from 
which my DB_bib Inerits the DB connection.

The thing is that I made a new class called DB_Debug which also inherits 
from DB_Main, and is there to have debugging data inserted into a table in 
the database.

I noticed that when the two objects are started (they both call the 
connection method using the same connection string) php doesn't 
initiate to distinct connections, but 1 connection within commands from 
both objects get passed to the DB server.

The problem is that query commands from the DB_Debug object and from the 
DB_Bib object get mixed up in the same connection, making it deficult to 
know when to make a commit.

Is there a way to fix this without having to change the connection string?

--
  21:50:04 up 2 days,  9:07,  0 users,  load average: 0.92, 0.37, 0.18
---------------------------------------------------------
Lic. Martín Marqués         |   SELECT 'mmarques' || 
Centro de Telemática        |       '@' || 'unl.edu.ar';
Universidad Nacional        |   DBA, Programador,
     del Litoral             |   Administrador
---------------------------------------------------------


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

* Re: 2 distinct connections
@ 2006-05-27 13:12  Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
  parent: Martin Marques <martin@bugs.unl.edu.ar>
  1 sibling, 1 reply; 4+ messages in thread

From: Cornelia Boenigk @ 2006-05-27 13:12 UTC (permalink / raw)
  To: Martin Marques <martin@bugs.unl.edu.ar>; +Cc: pgsql-php

Hi Martin

Did you try passing the constant PGSQL_CONNECT_FORCE_NEW to the 
Debug-connect?

regards
Conni



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

* Re: 2 distinct connections
@ 2006-05-27 14:39  Martin Marques <martin@bugs.unl.edu.ar>
  parent: Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
  0 siblings, 0 replies; 4+ messages in thread

From: Martin Marques @ 2006-05-27 14:39 UTC (permalink / raw)
  To: Cornelia Boenigk <poppcorn@cornelia-boenigk.de>; +Cc: pgsql-php

On Sat, 27 May 2006, Cornelia Boenigk wrote:

> Hi Martin
>
> Did you try passing the constant PGSQL_CONNECT_FORCE_NEW to the 
> Debug-connect?

Excelente. I forgot to say that I'm working with PEAR::DB, and just found 
this in DB/pgsql.php:

         if (isset($dsn['new_link'])
             && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true))
         {
             if (version_compare(phpversion(), '4.3.0', '>=')) {
                 $params[] = PGSQL_CONNECT_FORCE_NEW;
             }
         }

I always forget to "use the source Luke!" :-)

thanks!

--
  21:50:04 up 2 days,  9:07,  0 users,  load average: 0.92, 0.37, 0.18
---------------------------------------------------------
Lic. Martín Marqués         |   SELECT 'mmarques' || 
Centro de Telemática        |       '@' || 'unl.edu.ar';
Universidad Nacional        |   DBA, Programador,
     del Litoral             |   Administrador
---------------------------------------------------------


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

* Re: 2 distinct connections
@ 2006-05-27 14:40  Volkan YAZICI <yazicivo@ttnet.net.tr>
  parent: Martin Marques <martin@bugs.unl.edu.ar>
  1 sibling, 0 replies; 4+ messages in thread

From: Volkan YAZICI @ 2006-05-27 14:40 UTC (permalink / raw)
  To: Martin Marques <martin@bugs.unl.edu.ar>; +Cc: pgsql-php

On May 27 09:37, Martin Marques wrote:
> We're working on a project using PHP and PostgreSQL, mainly trying to work 
> in an OOP fashion. The project has quite a good amount of code, and a DB 
> Object called DB_Bib that has all the query methods. I also have a generic 
> DB object (DB_Main) which has code to establesh the connection, and from 
> which my DB_bib Inerits the DB connection.
> 
> The thing is that I made a new class called DB_Debug which also inherits 
> from DB_Main, and is there to have debugging data inserted into a table in 
> the database.
> 
> I noticed that when the two objects are started (they both call the 
> connection method using the same connection string) php doesn't 
> initiate to distinct connections, but 1 connection within commands from 
> both objects get passed to the DB server.
> 
> The problem is that query commands from the DB_Debug object and from the 
> DB_Bib object get mixed up in the same connection, making it deficult to 
> know when to make a commit.

As Cornelia Boenig suggested, you can force pg_connect() to establish a new
connection on every call. Also if you don't want to exhaust max_connections
limit, you can serialize queries using semaphores (or mutex).


Regards.



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


end of thread, other threads:[~2006-05-27 14:40 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-05-27 12:37 2 distinct connections Martin Marques <martin@bugs.unl.edu.ar>
2006-05-27 13:12 ` Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
2006-05-27 14:39   ` Martin Marques <martin@bugs.unl.edu.ar>
2006-05-27 14:40 ` Volkan YAZICI <yazicivo@ttnet.net.tr>

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