pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_pconnect+PostgreSQL cursors
4+ messages / 4 participants
[nested] [flat]

* pg_pconnect+PostgreSQL cursors
@ 2002-12-26 16:59 Sergei Levchenko <serg@city.gov.te.ua>
  2003-01-03 04:20 ` Re: pg_pconnect+PostgreSQL cursors Keary Suska <hierophant@pcisys.net>
  0 siblings, 1 reply; 4+ messages in thread

From: Sergei Levchenko @ 2002-12-26 16:59 UTC (permalink / raw)
  To: pgsql-php

Hi all

<?
$connection = pg_pconnect("dbname=$db user=$user password=$password");    
if (!isset($page)) 
{
	pg_exec($connection, "BEGIN WORK");
	pg_exec($connection, "DECLARE all_data CURSOR FOR SELECT id,body FROM test")
}

$result = pg_exec($connection, "FETCH 1 FROM all_data");
$info = pg_fetch_array($result, 0);
print "|$info[0]|$info[1]|<br>\n";
?>

When I execute this script at first without page parameter I'v got data to info array! when I execute it at other times I'v got nothing :(

I've got closing of cursor and transaction! why??? I use permanent connection, why I've got closing of cursor and transaction!???

-- 
WBR, sector119



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

* Re: pg_pconnect+PostgreSQL cursors
  2002-12-26 16:59 pg_pconnect+PostgreSQL cursors Sergei Levchenko <serg@city.gov.te.ua>
@ 2003-01-03 04:20 ` Keary Suska <hierophant@pcisys.net>
  0 siblings, 0 replies; 4+ messages in thread

From: Keary Suska @ 2003-01-03 04:20 UTC (permalink / raw)
  To: pgsql-php

on 12/26/02 9:59 AM, serg@city.gov.te.ua purportedly said:

> I've got closing of cursor and transaction! why??? I use permanent connection,
> why I've got closing of cursor and transaction!???

The "p" in "pconnect" means *persistent*, not permanent. The connection will
persist after the script has completed, however, the connection is handled
by the web server process and its true lifetime is only the lifetime of the
process. For Apache, this will vary by configuration, and is difficult to
predict when hosting multiple sites.

Tip: persistent connections are only useful when you want (and have the
resources to support) to minimize connection overhead. Any other use and you
are likely to be severely disappointed.

Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"




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

* pg_pconnect+PostgreSQL cursors
@ 2002-12-27 06:10 sector119@mail.ru
  2002-12-27 09:13 ` Re: pg_pconnect+PostgreSQL cursors Andrew McMillan <andrew@catalyst.net.nz>
  0 siblings, 1 reply; 4+ messages in thread

From: sector119@mail.ru @ 2002-12-27 06:10 UTC (permalink / raw)
  To: pgsql-php

Hi all

<?
$connection = pg_pconnect("dbname=$db user=$user password=$password");    
if (!isset($page)) 
{
	pg_exec($connection, "BEGIN WORK");
	pg_exec($connection, "DECLARE all_data CURSOR FOR SELECT id,body FROM test")
}

$result = pg_exec($connection, "FETCH 1 FROM all_data");
$info = pg_fetch_array($result, 0);
print "|$info[0]|$info[1]|<br>\n";
?>

When I execute this script at first without page parameter I'v got data to info array! when I execute it at other times I'v got nothing :(

I've got closing of cursor and transaction! why??? I use permanent connection, why I've got closing of cursor and transaction!???

-- 
WBR, sector119



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

* Re: pg_pconnect+PostgreSQL cursors
  2002-12-27 06:10 pg_pconnect+PostgreSQL cursors sector119@mail.ru
@ 2002-12-27 09:13 ` Andrew McMillan <andrew@catalyst.net.nz>
  0 siblings, 0 replies; 4+ messages in thread

From: Andrew McMillan @ 2002-12-27 09:13 UTC (permalink / raw)
  To: sector119@mail.ru; +Cc: pgsql-php

On Fri, 2002-12-27 at 19:10, sector119@mail.ru wrote:
> Hi all
> 
> <?
> $connection = pg_pconnect("dbname=$db user=$user password=$password");    
> if (!isset($page)) 
> {
> 	pg_exec($connection, "BEGIN WORK");
> 	pg_exec($connection, "DECLARE all_data CURSOR FOR SELECT id,body FROM test")
> }
> 
> $result = pg_exec($connection, "FETCH 1 FROM all_data");
> $info = pg_fetch_array($result, 0);
> print "|$info[0]|$info[1]|<br>\n";
> ?>
> 
> When I execute this script at first without page parameter I'v got
> data to info array! when I execute it at other times I'v got nothing
> :(
> 
> I've got closing of cursor and transaction! why??? I use permanent
> connection, why I've got closing of cursor and transaction!???

I'm not sure, from your description, but it may be something to do with
the fact that Apache allocates a server process to serve requests in a
round-robin fashion.

If you use Persistent connections, you will (most likely) get a
different database connection for each request (the apache process
connects persistently to the database, but your client session doesn't
connect persistently to any given apache process).

So it could be that you are seeing a previously opened cursor - default
Apache setups for development usually only have five processes serving
requests, so they go round fairly quickly.

If this is the case, I would imagine you would be seeing all sorts of
other wierd side-effects as well.

In general, cursors aren't the right answer to the problem when doing
web development.  Personally I have _never_ found a web problem which
they are suited to with PostgreSQL (although I have with Oracle).

PostgreSQL's " OFFSET <x> LIMIT <y> " functionality has been quite
useful, however.

Regards,
					Andrew.
-- 
---------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/         PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201     MOB: +64(21)635-694    OFFICE: +64(4)499-2267
           Survey for nothing with http://survey.net.nz/ 
---------------------------------------------------------------------




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


end of thread, other threads:[~2003-01-03 04:20 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-12-26 16:59 pg_pconnect+PostgreSQL cursors Sergei Levchenko <serg@city.gov.te.ua>
2003-01-03 04:20 ` Keary Suska <hierophant@pcisys.net>
2002-12-27 06:10 pg_pconnect+PostgreSQL cursors sector119@mail.ru
2002-12-27 09:13 ` Andrew McMillan <andrew@catalyst.net.nz>

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